QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#110396#5526. Jewel of Data Structure ProblemsAdp_DWA 11ms3484kbC++141.1kb2023-06-01 20:50:102023-06-01 20:50: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-06-01 20:50:14]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3484kb
  • [2023-06-01 20:50:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define RI register int
inline int read() {
    RI x=0, w=0;register char ch=0;
    while(!isdigit(ch)) w|=ch=='-', ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
    return w?-x:x;
}
const int MAXN=2e5+1;
int N, Q, a[MAXN], tree[MAXN];
inline int lowbit(int x) { return x&-x; }
inline void upd(int i) { for(;i<=N;i+=lowbit(i)) tree[i]++; }
inline int ask(int i) { int ans=0; for(;i;i-=lowbit(i)) ans+=tree[i]; return ans; }  
signed main() {
//	freopen("a.in","r",stdin);
	N=read(), Q=read(); int tot1=0, tot2=0, x, y; bool flag=0;
	for(RI i=1;i<=N;i++) a[i]=read(), tot1+=a[i]==i, tot2+=(a[i]+i)&1;
	for(RI i=1;i<=N;i++) {
		flag^=ask(a[i])&1;
		upd(a[i]);	
	} 
	for(RI i=1;i<=Q;i++) {
		x=read(), y=read(); swap(a[x],a[y]);
		tot1+=(a[y]==y)+(a[x]==x)-(a[y]==x)-(a[x]==y);
		tot2+=((a[y]+y)&1)+((a[x]+x)&1)-((a[x]+y)&1)-((a[y]+x)&1);
		if(flag^(i&1)) printf("%d\n",N);
		else {
			if(tot1==N) printf("%d\n",-1); 
			else if(tot2) 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: 3456kb

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: -100
Wrong Answer
time: 11ms
memory: 3484kb

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

output:

1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
...

result:

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