QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84124 | #5665. AA Country and King Dreamoon | HOLIC# | WA | 44ms | 9840kb | C++20 | 3.3kb | 2023-03-05 17:22:07 | 2023-03-06 01:00:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 6e5 + 10;
int a[N], pos[N], fa[N], pas[N], n;
inline void work(int c, int d){
int st = c;
for(int i = c; i <= d; ++i) pos[a[i]] = 0;
int al = (d - c) / 2;
for(int i = c; i <= d; ++i){
if(a[i]){
if(pos[a[i]]) --al;
else pos[a[i]] = i, fa[a[i]] = a[i - 1];
}
}
int now = a[c], p = 2; fa[now] = 2e9;
for(int i = c; i <= d; ++i){
if(!a[i]){
while(p <= n && pas[p]) ++ p;
if(al){
if(fa[now] < p){
a[i] = now = fa[now], --al;
}else{
fa[p] = now, a[i] = now = p; ++p;
}
}else{
fa[p] = now, a[i] = now = p, ++p;
}
}else{
now = a[i];
}
}
}
int main(){
int T;
scanf("%d", &T);
while(T --){
scanf("%d", &n);
for(int i = 1; i <= n; ++i) pos[i] = fa[i] = pas[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;
pas[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;
int po = st;
while(po <= n && al && fa[now] > po && pas[po] && (pas[po] - i) % 2 != 0){
++po;
while(po <= n && pos[po]) ++po;
continue;
}
if(al){
if(fa[now] < po){
--al;
a[i] = now = fa[now];
}else{
fa[po] = now, a[i] = now = po; pos[po] = i;
if(pas[po]){
work(i, pas[po]);
break;
}
st += (po == st);
}
}else{
while(pas[st] && st <= n) ++st;
fa[st] = now, a[i] = now = st; ++st;
}
}
}
}else{
work(pos[a[r + 1]], r + 1);
}
}
for(int i = 1; i <= m; ++i) printf("%d ", a[i]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9840kb
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: 44ms
memory: 9604kb
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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