QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84112 | #5665. AA Country and King Dreamoon | HOLIC# | WA | 42ms | 7624kb | C++20 | 3.0kb | 2023-03-05 16:22:27 | 2023-03-06 01:00:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 6e5 + 10;
int a[N], pos[N], fa[N];
int main(){
int T;
scanf("%d", &T);
while(T --){
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) pos[i] = fa[i] = 0;
int m = n + n - 1;
int al = n - 1;
for(int i = 1; i <= m; ++i){
scanf("%d", &a[i]);
if(i == 1 || i == m) a[i] = 1;
if(a[i]){
if(pos[a[i]]) -- al;
else pos[a[i]] = i;
}
}
int l = -1, r;
for(int i = 2; i < m; ++i){
if(!a[i]){
l = i;
for(int j = i; j < m; ++j){
if(!a[j]) r = j;
else break;
}
break;
}
}
if(l != -1){
if(pos[a[r + 1]] == r + 1){
for(int i = 1; i <= n; ++i) pos[i] = 0;
pos[1] = 1; fa[1] = 2e9;
int now = 1, st = 2; a[1] = a[m] = 1;
for(int i = 2; i < m; ++i){
if(a[i]){
if(!pos[a[i]]) fa[a[i]] = a[i - 1];
pos[a[i]] = i; now = a[i];
}else{
while(st <= n && pos[st]) ++st;
if(al){
if(fa[now] < st){
--al;
a[i] = fa[now]; now = fa[now];
}else{
fa[st] = now, a[i] = now = st; ++st;
}
}else{
fa[st] = now, a[i] = now = st; ++st;
}
}
}
}else{
int st = pos[a[r + 1]];
for(int i = st; i <= r + 1; ++i){
pos[a[i]] = 0;
}
int al = (r + 1 - st) / 2;
for(int i = st; i <= r + 1; ++i){
if(a[i]){
if(pos[a[i]]) --al;
else pos[a[i]] = i, fa[a[i]] = a[i - 1];
}
}
int now = a[r + 1], p = 2; fa[now] = 2e9;
for(int i = st + 1; i <= r; ++i){
if(!a[i]){
while(p <= n && pos[p]) ++ p;
if(al){
if(fa[now] < p){
now = fa[now], --al; a[i] = now;
}else{
fa[p] = now, a[i] = now = p; ++p;
}
}else{
fa[p] = now, a[i] = now = p, ++p;
}
}else{
now = a[i];
}
}
}
}
for(int i = 1; i <= m; ++i) printf("%d ", a[i]);
puts("");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 7616kb
input:
9 5 1 2 3 2 0 2 1 5 1 5 1 2 3 0 0 2 1 5 1 5 1 2 0 0 0 2 1 5 1 5 1 2 0 0 0 0 1 5 1 5 1 0 0 0 0 0 1 5 1 5 1 0 0 0 0 0 0 5 1 5 1 0 0 0 0 0 0 0 1 5 1 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0
output:
1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1
result:
ok 9 lines
Test #2:
score: -100
Wrong Answer
time: 42ms
memory: 7624kb
input:
28668 2 0 2 1 2 0 0 1 2 0 0 0 2 1 0 1 2 1 0 0 2 1 2 0 3 0 2 1 3 1 3 0 0 1 3 1 3 0 0 0 3 1 3 0 0 0 0 1 3 0 0 0 0 0 3 1 0 1 3 1 3 1 0 0 3 1 3 1 0 0 0 1 3 1 0 0 0 0 3 1 2 0 3 1 3 1 2 0 0 1 3 1 2 0 0 0 3 1 2 1 0 1 3 1 2 1 0 0 3 1 2 1 3 0 3 0 2 3 2 1 3 0 0 3 2 1 3 0 0 0 2 1 3 1 0 3 2 1 3 1 0 0 2 1 3 1 2 ...
output:
1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 1 3 1 1 2 3 2 1 1 2 3 2 1 1 2 1 2 1 1 2 3 2 1 1 2 1 2 1 1 2 3 2 1 1 2 3 2 1 1 2 3 2 1 1 2 3...
result:
wrong answer 24th lines differ - expected: '1 2 3 2 1', found: '1 2 1 2 1 '