E. XOR and favorite numbertime limit per test4 secondsmemory limit per test256 megabytesinputstandard Inputoutputstandard Output
Bob has a favorite numberkanda i of length n. Now he asks your to answer m queries. Each query was given by a pair li and Ri and asks you to count th E number of pairs of integers i and J, such that l ≤ i ≤ j ≤ R and the xor of the numbers ai, ai + 1,.. ., aJ is equal to k.
Input
The first line of the input contains integers n, m and k (1≤ n, m ≤100, 0≤ k ≤1)-the length of the array, the number of queries and Bob's favorite num ber respectively.
The second line contains n integers ai (0≤ a I ≤1)-bob ' s array.
Then m lines follow. The i-th line contains integers li and Ri (1≤ L i ≤ ri ≤ n)-the parameters of the i-th query.
Output
Print m lines, answer the queries in the order they appear in the input.
Examplesinput
6 2 3
1 2 1 1 0 3
1 6
3 5
Output
7
0
Input
5 3 1
1 1 1) 1 1
1 5
2 4
1 3
Output
9
4
4
Note
In the first sample the suitable pairs of i and J for the first query is: (1, 2), ( 1, 4), (1, 5), ( 2,3 ), (3, 6), (5, 6), (6, 6). Not a single of these pairs are suitable for the second query.
In the second, the sample XOR equals 1 for any subarrays of an odd length.
Test instructions: Find out how many pairs of xor and the logarithm of k are in the interval;
Idea: Mo team algorithm, mainly how O (1) update, a[l]^a[l+1].....^a[r]=pre[r]^pre[l-1]=k;pre[i] means a[1]^a[2]^....^a[i];
Pos[r]^pre[l-1]=k; pre[r]=pre[l-1]^k; update the pre;
#include <bits/stdc++.h>using namespacestd;#definell Long Long#definePi (4*atan (1.0))Const intn=1e5+Ten, m=4e6+Ten, inf=1e9+Ten, mod=1e9+7;Constll inf=1e18+Ten;intSi[n];struct is{ intL,r,pos; BOOL operator< (Const is&B)Const { if(si[l]==SI[B.L])returnr<B.R; returnsi[l]<SI[B.L]; }}q[n];intA[n];intn,m,k;intL,r;ll out[N],ans;intflag[m<<1];voidAddintPOS) {ans+=flag[k^A[pos]]; Flag[a[pos]]++;}voidDelintPOS) {Flag[a[pos]]--; Ans-=flag[k^A[pos]];}intMain () {scanf ("%d%d%d",&n,&m,&k); intKuai=sqrt (n); for(intI=1; i<=n;i++) scanf ("%d", &a[i]), si[i]= (i-1)/kuai+1, a[i]^=a[i-1]; for(intI=1; i<=m;i++) scanf ("%d%d", &Q[I].L,&Q[I].R), q[i].pos=i; Sort (q+1, q+m+1); L=1; R=0; Ans=0; flag[0]=1; for(intI=1; i<=m;i++) { while(l<Q[I].L) {del (l-1); L++; } while(l>Q[I].L) {L--; Add (L-1); } while(r<Q[I].R) {R++; Add (R); } while(r>Q[I].R) {del (R); R--; } out[q[i].pos]=ans; } for(intI=1; i<=m;i++) printf ("%lld\n", out[i]); return 0;}
Codeforces Round #340 (Div. 2) E. XOR and favorite number MO team algorithm