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

Source: Internet
Author: User

E. XOR and favorite number

Bob has a favorite numberkanda i  of length  n . Now he asks your to Answer  m  queries. Each query was given by a pair  l i  and   R i  and asks you to count the number of Pairs of Integers  i  and  J , such That  l i j R  and The XOR of the numbers < Span class= "Tex-span" > a i , a I + 1, ..., a J  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 Number 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.

Examples input
6 2 3
1 2 1 1 0 3
1 6
3 5
Output
7
0
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

  

Give you a sequence of length n

M inquiries, every time you ask how many pairs of l,r between the sub-range are equal to K

Exercises

Godless, a team of Mo.

#include <bits/stdc++.h>using namespacestd;Const intN = 1e6+Ten, M = 5e6+Ten, INF = 1e9+7, mod = 1e9+7;intH[m];intSum[n],n,m,k,a[n],pos[n];Long LongAn[n],ans;structss{intL,r,id;} Q[n];intCMP (ss S1,ss S2) {if(POS[S1.L]==POS[S2.L])returns1.r<s2.r;Else returns1.l<S2.L;}intCmpl (ss S1,ss S2) {returns1.id<s2.id;}voidUpdateintPintadd) {    if(add==-1) {H[sum[p]]--; Ans-= h[sum[p]^K]; }    Else{ans+ = h[sum[p]^K]; H[SUM[P]]++; }}intMain () {scanf ("%d%d%d",&n,&m,&k);  for(intI=1; i<=n;i++) scanf ("%d",&A[i]); h[0] =1;  for(intI=1; i<=n;i++) Sum[i] = sum[i-1] ^A[i];  for(intI=1; i<=m;i++) {scanf ("%d%d",&q[i].l,&Q[I].R); Q[i].id=i; }    intBlock = (int) sqrt (Double) n +0.5);  for(intI=1; i<=n;i++) Pos[i] = (i1)/block +1; Sort (q+1, q+m+1, CMP);  for(intI=1, l=1, r=0; i<=m;i++) {         for(; r<q[i].r;r++) Update (r+1,1);  for(; l>q[i].l;l--) Update (L-2,1);  for(; r>q[i].r;r--) Update (r,-1);  for(; l<q[i].l;l++) Update (L-1,-1); An[q[i].id]=ans; }     for(intI=1; i<=m;i++) printf ("%i64d\n", An[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.