QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#78559#5526. Jewel of Data Structure ProblemsPeanut_TangWA 2ms3576kbC++14759b2023-02-19 14:42:562023-02-19 14:42:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-19 14:42:58]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3576kb
  • [2023-02-19 14:42:56]
  • 提交

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'