QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#110396 | #5526. Jewel of Data Structure Problems | Adp_D | WA | 11ms | 3484kb | C++14 | 1.1kb | 2023-06-01 20:50:10 | 2023-06-01 20:50:14 |
Judging History
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;
}
詳細信息
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'