QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883608 | #8240. Card Game | zqiaor | RE | 374ms | 164680kb | C++17 | 1.2kb | 2025-02-05 17:16:15 | 2025-02-05 17:16:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define mid (l+r>>1)
int n,q,a[300005],la[300005],tot,root[300005],lans;
struct node{int ls,rs,s;}tr[15000005];
void update(int &rt,int l,int r,int x,int y){
tr[++tot]=tr[rt],rt=tot;
if(x<=l&&r<=y){tr[rt].s++;return;}
if(x<=mid)update(tr[rt].ls,l,mid,x,y);
if(mid<y)update(tr[rt].rs,mid+1,r,x,y);
}
void copy(int &rt1,int rt2,int l,int r,int x,int y){
tr[++tot]=tr[rt1],rt1=tot;
if(x<=l){tr[rt1]=tr[rt2],tr[rt1].s-=y;return;}
if(x<=mid)copy(tr[rt1].ls,tr[rt2].ls,l,mid,x,y+tr[rt1].s);
copy(tr[rt1].rs,tr[rt2].rs,mid+1,r,x,y+tr[rt1].s);
}
int query(int rt,int l,int r,int x){
if(!rt)return 0;
if(l==r)return tr[rt].s;
if(x<=mid)return tr[rt].s+query(tr[rt].ls,l,mid,x);
else return tr[rt].s+query(tr[rt].rs,mid+1,r,x);
}
int 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],la[i]=n+1;
for(int i=n,j;i>=1;i--){
j=la[a[i]],la[a[i]]=i,root[i]=root[i+1],update(root[i],1,n,i,j-1);
if(j<=n)copy(root[i],root[j+1],1,n,j,0);
}
for(int i=1,l,r;i<=q;i++)cin>>l>>r,l^=lans,r^=lans,cout<<(lans=query(root[l],1,n,r))<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5632kb
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: 0ms
memory: 5848kb
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: 0
Accepted
time: 5ms
memory: 11088kb
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 31 35 76 35 9 63 27 30 38 72 22 133 45 71 92 22 49 25 47 56 30 32 87 90 31 50 56 76 108 69 60 56 90 104 59 107 40 53 46 50 82 92 20 34 85 90 8 36 58 74 66 72 7 47 16 33 52 17 28 51 16 51 41 61 139 45 34 23 43 25 40 81 30 93 134 61 61 77 78 63 14 46 86 35 115 16 32 27 67 78 22 13 25 69 18 30 22 93 ...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 374ms
memory: 164680kb
input:
300000 300000 247458 294756 90122 232046 27674 270860 146526 49400 98719 7831 68724 276111 113048 4028 56028 219364 188447 275016 284924 189020 57763 150969 208171 148849 58503 250276 15479 72273 299297 165871 20928 195677 130684 192311 298330 268331 83030 298060 35631 209221 170402 38800 53211 6839...
output:
801 801 1149 180 334 296 937 478 345 1416 747 259 179 482 664 333 836 1031 610 583 520 812 1386 528 449 1083 419 483 771 435 746 880 686 427 779 431 990 1906 622 757 332 567 91 565 226 446 240 691 414 815 382 668 1291 1059 1231 835 720 322 1403 935 281 581 613 253 959 759 325 594 115 525 559 1244 14...
result:
ok 300000 numbers
Test #5:
score: -100
Runtime Error
input:
300000 300000 88317 78932 58744 99868 5348 83581 56139 42780 17801 50414 28414 21205 48548 34313 71524 14868 8837 27236 54629 58491 16139 5706 88316 71645 46350 25945 1082 84228 5014 82628 65218 76940 35489 63410 37867 26565 24641 67133 72001 73332 45116 40405 20933 5650 86506 32155 15336 99468 6604...