QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85910#5665. AA Country and King DreamoonyyyyxhWA 1ms1748kbC++141.4kb2023-03-08 21:08:542023-03-08 21:09:14

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:09:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:1748kb
  • [2023-03-08 21:08:54]
  • 提交

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];
int stk[N],tp;
int seq[N],rk;
bool rem[N],del[N],ins[N];
int lis[N],m;
void solve(){
	n=read();
	for(int i=1;i<n+n;++i) a[i]=read();
	for(int i=1;i<=n;++i) rem[i]=del[i]=ins[i]=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;
	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;}
		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: 0
Wrong Answer
time: 1ms
memory: 1748kb

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

result:

wrong answer 2nd lines differ - expected: '1 2 3 2 4 2 1 5 1', found: '1 2 3 2 1061109567 2 1 5 1 '