Codeforces Round #340 (Div. 2) E. XOR and favorite number MO team algorithm

Source: Internet
Author: User

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 lij 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 irin)-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&AMP;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", &AMP;Q[I].L,&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.