QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85915#5665. AA Country and King DreamoonyyyyxhWA 22ms1528kbC++141.5kb2023-03-08 21:12:422023-03-08 21:12:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-08 21:12:45]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:1528kb
  • [2023-03-08 21:12:42]
  • 提交

answer

#include <cstdio>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=(x<<1)+(x<<3)+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=1000003;
int n;
int a[N],b[N];
int stk[N],tp;
int seq[N],rk;
bool rem[N],del[N],ins[N];
void solve(){
	n=read();
	for(int i=1;i<n+n;++i) a[i]=b[i]=read();
	for(int i=1;i<=n;++i) rem[i]=del[i]=ins[i]=0;
	tp=0;
	for(int i=n+n-1;i;--i){
		if(!a[i]) break;
		if(tp>1&&a[i]==stk[tp-1]) del[stk[tp--]]=1;
		else stk[++tp]=a[i];
	}
	rk=tp;
	for(int i=1;i<=tp;++i) rem[seq[i]=stk[i]]=1;
	int x;
	tp=0;
	for(x=1;x<n+n;++x){
		if(!a[x]) break;
		if(tp>1&&a[x]==stk[tp-1]) del[stk[tp--]]=1;
		else stk[++tp]=a[x];
	}
	for(int i=1;i<=tp;++i) ins[stk[i]]=1;
	int pos=1,p=1;
	for(;x<n+n;++x){
		if(a[x]) break;
		while(p<=n&&ins[p]||del[p]||rem[p]) ++p;
		while(pos<=rk&&ins[seq[pos]]) ++pos;
		int op=0,res=0x3f3f3f3f;
		if(!rem[stk[tp]]&&tp>1){
			if(stk[tp-1]<res){
				res=stk[tp-1];
				op=1;
			}
		}
		if(p<=n&&p<res){res=p;op=2;}
		if(pos<=rk&&seq[pos]<res){res=seq[pos];op=3;}
		if(!op){
			for(int i=1;i<(n+n);++i) printf("%d ",b[i]);
			putchar('\n');
			return;
		}
		a[x]=res;
		if(op==1){
			ins[stk[tp]]=0;
			del[stk[tp]]=1;
			--tp;
		}
		if(op==2){
			ins[stk[++tp]=p]=1;
		}
		if(op==3){
			ins[stk[++tp]=seq[pos]]=1;
		}
	}
	for(int i=1;i<n+n;++i) printf("%d ",a[i]);
	putchar('\n');
}
int main(){
	int tc=read();
	while(tc--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 1524kb

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: 22ms
memory: 1528kb

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 323rd lines differ - expected: '1 3 4 3 1 2 1', found: '1 3 4 0 0 2 1 '