QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#882176 | #8240. Card Game | DaiRuiChen007 | WA | 4ms | 9948kb | C++17 | 992b | 2025-02-04 21:39:58 | 2025-02-04 21:39:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5;
struct SegmentTree {
int tg[MAXN*100],ls[MAXN*100],rs[MAXN*100],m;
void add(int ul,int ur,int k,int l,int r,int q,int &p) {
if(ul<=l&&r<=ur) return tg[++m]=tg[q]+k,ls[m]=ls[q],rs[m]=rs[q],p=m,void();
int mid=(l+r)>>1; tg[++m]=tg[p],ls[m]=ls[p],rs[m]=rs[p],p=m;
k+=tg[p]-tg[q];
if(ul<=mid) add(ul,ur,k,l,mid,ls[q],ls[p]);
if(mid<ur) add(ul,ur,k,mid+1,r,rs[q],rs[p]);
}
int qry(int u,int l,int r,int p) {
if(l==r) return tg[p];
int mid=(l+r)>>1;
return tg[p]+(u<=mid?qry(u,l,mid,ls[p]):qry(u,mid+1,r,rs[p]));
}
} T;
int n,q,rt[MAXN],a[MAXN],to[MAXN];
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;++i) cin>>a[i],to[i]=n+1;
for(int i=n;i>=1;--i) {
rt[i]=rt[to[a[i]]+1],T.add(i,to[a[i]]-1,1,1,n,rt[i+1],rt[i]),to[a[i]]=i;
}
for(int l,r,lst=0;q--;) cin>>l>>r,l^=lst,r^=lst,cout<<(lst=T.qry(r,1,n,rt[l]))<<"\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7900kb
input:
5 5 3 3 1 1 1 5 5 3 4 3 3 0 5 3 5
output:
1 2 1 0 1
result:
ok 5 number(s): "1 2 1 0 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5856kb
input:
7 7 2 4 1 2 3 1 2 1 6 0 4 3 3 0 4 0 3 0 6 2 7
output:
2 1 1 1 2 3 0
result:
ok 7 numbers
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 9948kb
input:
10000 10000 160 120 157 1393 1368 911 449 735 662 698 480 730 1184 768 1291 1012 834 61 1925 642 1401 1681 441 367 1498 1215 1969 1895 857 304 400 524 1138 846 810 885 68 1737 199 90 321 1109 980 1097 1936 1482 753 1796 1787 1939 291 1201 1025 367 980 1785 1781 276 1774 777 861 967 1428 1060 1300 32...
output:
8 29 6 6 26 0 -17 0 48 70 30 9 -13 0 9 -16 0 64 -17 0 38 -52 0 -21 0 96 45 61 46 -54 0 33 42 8 63 -31 0 25 48 -21 0 -23 0 18 26 -2 0 34 -27 0 13 116 4 -63 0 7 61 30 3 23 20 25 42 31 -14 0 8 16 21 -27 0 5 -18 0 42 39 -54 0 75 36 45 -6 0 17 -12 0 0 31 15 14 26 17 19 7 1 -24 0 2 8 4 41 32 64 -8 0 0 -6 ...
result:
wrong answer 2nd numbers differ - expected: '31', found: '29'