标签:莫队 col pen mes typedef main its -- freopen
1 /* 2 题意: 3 思路: 4 时间: 5 */ 6 #include <bits/stdc++.h> 7 using namespace std; 8 9 typedef long long LL; 10 const int MAXN=100005; 11 const LL MOD7 = 1e9+7; 12 13 struct Query 14 { 15 int l,r; 16 int idx; 17 }Q[MAXN]; 18 19 int a[MAXN]; 20 int belong[MAXN],qsize,num; 21 LL flag[1<<20],Ans; 22 LL ans[MAXN]; 23 int n,m,K; 24 25 int cmp(Query oa,Query ob) 26 { 27 if (belong[oa.l]==belong[ob.l]) 28 return oa.r<ob.r; 29 return belong[oa.l]<belong[ob.l]; 30 } 31 32 void Add(int x) 33 { 34 Ans+=flag[a[x]^K]; 35 flag[a[x]]++; 36 } 37 void Delete(int x) 38 { 39 flag[a[x]]--; 40 Ans-=flag[a[x]^K]; 41 } 42 int main() 43 { 44 #ifndef ONLINE_JUDGE 45 freopen("test.txt","r",stdin); 46 #endif // ONLINE_JUDGE 47 scanf("%d%d%d",&n,&m,&K); 48 qsize=sqrt(n);num=qsize;if (num*num<n) ++num; 49 for (int i=1;i<=n;++i) 50 belong[i]=(i-1)/qsize+1; 51 for (int i=1;i<=n;++i) 52 { 53 scanf("%d",&a[i]); 54 a[i]^=a[i-1]; 55 } 56 int l=1,r=0; 57 Ans=0; 58 flag[0]=1; 59 for (int i=1;i<=m;++i) 60 { 61 scanf("%d%d",&Q[i].l,&Q[i].r); 62 Q[i].idx=i; 63 } 64 sort(Q+1,Q+1+m,cmp); 65 for (int i=1;i<=m;++i) 66 { 67 int idx=Q[i].idx; 68 while (l<Q[i].l) {Delete(l-1);++l;} 69 while (l>Q[i].l) {--l;Add(l-1);} 70 while (r<Q[i].r) {++r;Add(r);} 71 while (r>Q[i].r) {Delete(r);--r;} 72 ans[idx]=Ans; 73 } 74 for (int i=1;i<=m;++i) 75 printf("%I64d\n",ans[i]); 76 return 0; 77 }
标签:莫队 col pen mes typedef main its -- freopen
原文地址:https://www.cnblogs.com/LeeSongt/p/9338739.html