QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#882696 | #8240. Card Game | Kevin5307 | TL | 1ms | 7768kb | C++23 | 1.7kb | 2025-02-05 10:47:35 | 2025-02-05 10:47:43 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,q;
int a[300300];
int nxt[300300];
int pos[300300];
const int B=550;
int tr[B+5][300300],v[B+5][300300];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>a[i];
memset(pos,-1,sizeof(pos));
for(int i=n;i>=1;i--)
{
nxt[i]=pos[a[i]];
pos[a[i]]=i;
}
for(int i=1;i<=n/B;i++)
{
int bound=i*B-1;
for(int j=bound;j>=1;j--)
if(nxt[j]==-1||nxt[j]/B>i)
{
tr[i][j]=tr[i][j+1];
v[i][j]=v[i][j+1]+1;
}
else if(nxt[j]/B==i)
{
tr[i][j]=j;
v[i][j]=0;
}
else
{
tr[i][j]=tr[i][nxt[j]+1];
v[i][j]=v[i][nxt[j]+1];
}
}
int lst=0;
while(q--)
{
int l,r;
cin>>l>>r;
l^=lst;
r^=lst;
int ans=0;
while(l/B!=r/B)
{
ans+=v[r/B][l];
l=tr[r/B][l];
if(l/B==r/B) break;
if(nxt[l]<=r) l=nxt[l]+1;
else ans++,l++;
}
while(l<=r)
{
if(nxt[l]<=r&&nxt[l]!=-1) l=nxt[l]+1;
else ans++,l++;
}
cout<<(lst=ans)<<'\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7664kb
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: 7768kb
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
Time Limit Exceeded
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...