QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109339 | #5665. AA Country and King Dreamoon | chenshi | WA | 44ms | 1584kb | C++ | 808b | 2023-05-28 16:30:12 | 2023-05-28 16:30:15 |
Judging History
answer
#include<cstdio>
using namespace std;
const int o=8e5;
int T,n,a[o],fa[o],lst[o],L,R;bool vis[o];
int main(){
for(scanf("%d",&T);T--;putchar('\n')){
scanf("%d",&n);R=-1;
for(int i=1;i<n*2;++i) scanf("%d",&a[i]);
for(int i=1;i<=n;++i) fa[i]=lst[i]=o,vis[i]=0;
a[1]=a[n*2-1]=1;vis[1]=1;
for(int i=n*2-2;i;vis[a[i--]]=1)
if(!a[i]){R=i;break;}
else if(a[i]^fa[a[i+1]]) fa[a[i]]=a[i+1],lst[a[i+1]]=a[i];
for(int i=2;i<n*2;vis[a[i++]]=1)
if(!a[i]){L=i;break;}
else if(a[i]^fa[a[i-1]]) fa[a[i]]=a[i-1];
for(int i=L,j=1;i<=R;vis[a[i++]]=1){
for(;j<=n&&vis[j];++j);
if(fa[a[i-1]]<j&&lst[fa[a[i-1]]]-a[i-1]) a[i]=fa[a[i-1]];
else if(lst[a[i-1]]<j) a[i]=lst[a[i-1]];
else fa[a[i]=j]=a[i-1];
}
for(int i=1;i<n*2;++i) printf("%d ",a[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 1560kb
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 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