QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108628#5526. Jewel of Data Structure Problemsgrass8cowWA 36ms3788kbC++14667b2023-05-25 20:15:492023-05-25 20:15:52

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-25 20:15:52]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:3788kb
  • [2023-05-25 20:15:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,q,p[201000],t,z;
void fk(int i,int f){
	t+=f*((i&1)!=(p[i]&1));
	if(i>1)z+=f*(p[i-1]<p[i]);
	if(i<n)z+=f*(p[i]<p[i+1]);
}
bool vi[201000];
int o;
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	o=(n&1);
	for(int i=1;i<=n;i++)if(!vi[i]){
		o^=1;int u=i;
		while(!vi[u])vi[u]=1,u=p[u];
	}
	for(int i=1;i<=n;i++)fk(i,1);
	for(int i=1,u,v;i<=q;i++){
		scanf("%d%d",&u,&v);o^=1;
		fk(u,-1),fk(v,-1);swap(p[u],p[v]);fk(u,1),fk(v,1);
		if(o)printf("%d\n",n);
		else if(z==2*(n-1))puts("-1");
		else if(t)printf("%d\n",n-1);
		else printf("%d\n",n-2);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3644kb

input:

5 6
2 1 3 4 5
1 2
1 2
1 4
2 1
3 5
1 3

output:

-1
5
4
5
3
5

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 36ms
memory: 3624kb

input:

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

result:

wrong answer 3rd numbers differ - expected: '2', found: '-1'