QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883751 | #8240. Card Game | zhulexuan | WA | 2ms | 15956kb | C++14 | 2.5kb | 2025-02-05 18:37:42 | 2025-02-05 18:37:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
T w=1; n=0; char ch=getchar();
while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
n*=w;
}
template<typename T>inline void write(T x){
if (x==0){ putchar('0'); return ; }
T tmp;
if (x>0) tmp=x;
else tmp=-x;
if (x<0) putchar('-');
char F[105];
long long cnt=0;
while (tmp){
F[++cnt]=tmp%10+48;
tmp/=10;
}
while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 300005;
struct Tree{
int cnt, rt[N];
struct node{
int lc,rc,v;
void init(){ lc = rc = v = 0; }
}t[64*N];
void build(){ t[cnt=0].init(); }
ll nww(){ t[++cnt].init(); return cnt; }
void add(int &s,int l,int r,int v,int pre,int L,int R){
if (!s) s = nww();
if (L>=l && R<=r){ t[s] = t[pre]; t[s].v += v; return ; }
int mid = (L+R)>>1;
if (l<=mid) add(t[s].lc,l,r,v,t[pre].lc,L,mid);
if (r>mid) add(t[s].rc,l,r,v,t[pre].rc,mid+1,R);
}
int qry(int s,int x,int L,int R){
// printf("qry %lld %lld , %lld ~ %lld\n",s,x,L,R);
if (!s) return 0;
int ans = t[s].v, mid = (L+R)>>1;
// printf("t[s].v = %lld\n",t[s].v);
if (x<=mid) ans += qry(t[s].lc,x,L,mid);
else ans += qry(t[s].rc,x,mid+1,R);
return ans;
}
}tr;
ll n,q;
ll a[N];
ll nx[N], pos[N];
int main(){
// freopen("a.in","r",stdin);
// freopen(".out","w",stdout);
ll i,j;
read(n), read(q);
fr(i,1,n) read(a[i]);
rfr(i,n,1) nx[i] = pos[a[i]], pos[a[i]] = i;
// fr(i,1,n) printf("nx[%lld] = %lld\n",i,nx[i]);
tr.build();
rfr(i,n,1){
if (!nx[i]) tr.add(tr.rt[i],i,n,1,tr.rt[i+1],1,n);
else{
tr.add(tr.rt[i],i,nx[i]-1,1,tr.rt[i+1],1,n);
tr.add(tr.rt[i],nx[i],n,0,tr.rt[nx[i]+1],1,n);
}
}
int ls = 0;
while (q--){
int l,r; read(l), read(r);
l ^= ls, r ^= ls;
ls = tr.qry(tr.rt[l],r,1,n);
write(ls), putchar('\n');
}
return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=512000000 -std=c++11 -O2
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9796kb
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: 11844kb
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: 2ms
memory: 15956kb
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 30 4 5 24 0 35 5 13 83 36 20 45 19 11 11 98 115 7 45 40 42 17 23 13 74 58 27 49 13 23 32 2 30 25 19 34 11 27 28 39 67 25 16 36 74 11 29 11 19 20 131 50 47 37 23 23 6 5 3 67 18 18 32 9 38 41 46 26 22 23 17 7 34 14 21 24 34 6 16 37 23 16 28 15 26 16 22 31 6 10 34 58 32 45 34 21 15 21 59 104 67 21 36...
result:
wrong answer 2nd numbers differ - expected: '31', found: '30'