Submission #64332276
Source Code Expand
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
#define MaxN 400005
int n, a[MaxN], l[MaxN], r[MaxN], ans;
void check(int a, int b) {
if (l[b] + 1 == r[b]) return ;
if (abs(l[a]-l[b])==1 && abs(r[a]-r[b])==1) ans++;
}
void work() {
ans = 0;
cin >> n;
for(int i = 1; i <= 2*n; i++) {
cin >> a[i];
if (l[a[i]] == 0) l[a[i]] = i;
else r[a[i]] = i;
}
for(int i = 1; i <= n; i++) { // 数字i是否能构造答案
if (l[i] + 1 == r[i]) continue;
if (l[a[l[i]+1]] == l[i]+1) check(i, a[l[i]+1]);
}
// for(int i = 1; i <= n; i++) {
// if (l[i] + 1 == r[i]) continue;
// for(int j = i+1; j <= n; j++) {
// if (l[j] + 1 == r[j]) continue;
// check(i, j);
// }
// }
cout << ans << endl;
for(int i = 1; i <= n; i++) l[i] = 0;
}
int main()
{
int T;
cin >> T;
while (T--) {
work();
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Switch Seats |
| User | gobywind |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 899 Byte |
| Status | AC |
| Exec Time | 92 ms |
| Memory | 6788 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 02_random_1_00.txt, 02_random_1_01.txt, 02_random_1_02.txt, 02_random_1_03.txt, 02_random_1_04.txt, 03_random_2_00.txt, 03_random_2_01.txt, 03_random_2_02.txt, 04_max_00.txt, 05_corner_00.txt, 05_corner_01.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3468 KiB |
| 01_small_00.txt | AC | 81 ms | 3628 KiB |
| 01_small_01.txt | AC | 80 ms | 3464 KiB |
| 01_small_02.txt | AC | 61 ms | 3468 KiB |
| 01_small_03.txt | AC | 61 ms | 3688 KiB |
| 01_small_04.txt | AC | 61 ms | 3568 KiB |
| 01_small_05.txt | AC | 61 ms | 3508 KiB |
| 01_small_06.txt | AC | 61 ms | 3552 KiB |
| 02_random_1_00.txt | AC | 86 ms | 6672 KiB |
| 02_random_1_01.txt | AC | 86 ms | 6656 KiB |
| 02_random_1_02.txt | AC | 84 ms | 6620 KiB |
| 02_random_1_03.txt | AC | 92 ms | 6776 KiB |
| 02_random_1_04.txt | AC | 90 ms | 6628 KiB |
| 03_random_2_00.txt | AC | 84 ms | 6624 KiB |
| 03_random_2_01.txt | AC | 82 ms | 6584 KiB |
| 03_random_2_02.txt | AC | 81 ms | 6788 KiB |
| 04_max_00.txt | AC | 68 ms | 6624 KiB |
| 05_corner_00.txt | AC | 70 ms | 6588 KiB |
| 05_corner_01.txt | AC | 70 ms | 6596 KiB |