QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109339#5665. AA Country and King DreamoonchenshiWA 44ms1584kbC++808b2023-05-28 16:30:122023-05-28 16:30:15

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-28 16:30:15]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:1584kb
  • [2023-05-28 16:30:12]
  • 提交

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 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: 1584kb

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 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3...

result:

wrong answer 32nd lines differ - expected: '1 3 1 2 1', found: '1 2 1 2 1 '