QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#78559 | #5526. Jewel of Data Structure Problems | Peanut_Tang | WA | 2ms | 3576kb | C++14 | 759b | 2023-02-19 14:42:56 | 2023-02-19 14:42:58 |
Judging History
answer
#include <bits/stdc++.h>
const int N=2e5+5;
int n,q,x,y,z,a[N];
struct BIT
{
int c[N];
void Add(int x){for ( ; x<=n; x+=x&-x) c[x]^=1;}
int Sum(int x){int E=0; for ( ; x; x-=x&-x) E^=c[x]; return E;}
}T;
int main()
{
scanf("%d%d",&n,&q); int i,j;
for (i=1; i<=n; i++) scanf("%d",a+i),x+=a[i]==i,y+=(a[i]+i&1);
for (i=n; i; i--) z^=T.Sum(a[i]),T.Add(a[i]);
printf("%d %d %d\n",x,y,z);
while (q--)
{
scanf("%d%d",&i,&j),x-=(a[i]==i)+(a[j]==j),y-=(a[i]+i&1)+(a[j]+j&1);
std::swap(a[i],a[j]),x+=(a[i]==i)+(a[j]==j),y+=(a[i]+i&1)+(a[j]+j&1),z^=1;
if (z&1) printf("%d\n",n);
else if (x==n) puts("-1");
else printf("%d\n",n-1-!y);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3576kb
input:
5 6 2 1 3 4 5 1 2 1 2 1 4 2 1 3 5 1 3
output:
3 2 1 -1 5 4 5 3 5
result:
wrong answer 1st numbers differ - expected: '-1', found: '3'