Topic Links:
Codeforces 617 E. XOR and favorite number
Title Description:
Give the number of N, m query, each query in the interval [L, R] How many pairs (I, j), meet Ai ^ ai+1 ^ ai+2 ^ ... ^ aj-1 ^ aj = k
Problem Solving Ideas:
MO team algorithm, in the linear complexity of the transfer, the problem key in and how to carry out state transfer, we set Sum[i] for [1, I] interval within the XOR, for the interval [a, b] xor and for sum[b] ^ sum[a-1]. If the interval [a, b] of the XOR and K, then there is sum[b] ^ sum[a-1] = = k, due to the nature of the XOR can be inferred: sum[b] ^ k = = Sum[a-1],sum[a-1] ^ k = = Sum[b].
1 /**2 ans to use LL,3 num[] to expand twice times in the range of K4 */5#include <math.h>6#include <cstdio>7#include <cstring>8#include <iostream>9#include <algorithm>Ten using namespacestd; One A typedef __int64 LL; - Const intMAXN =100010; - structnode the { - intL, R, id; - } Q[MAXN]; - LL ANS[MAXN]; + intB[MAXN], num[maxn* -]; - intN, m, k, LB; + A BOOLCMP (node x, node Y) at { - if(x.l/lb = = Y.L/lb) - returnX.R <Y.R; - returnX.L <Y.L; - } - voidSolve () in { - intL, R; to LL tmp; +L = r = tmp =0; -num[0] =1; the * for(intI=0; i<m; i++) $ {Panax Notoginseng while(R <Q[I].R) - { theR + +; +TMP + = num[b[r]^K]; ANUM[B[R]] + +; the } + - while(R >Q[I].R) $ { $NUM[B[R]]--; -TMP-= num[b[r]^K]; -R--; the } - Wuyi while(L < Q[I].L-1) the { -NUM[B[L]]--; WuTMP-= num[b[l] ^K]; -L + +; About } $ - while(L > Q[I].L-1) - { -L--; ATMP + = Num[b[l] ^K]; +NUM[B[L]] + +; the } - $Ans[q[i].id] =tmp; the } the } the the intMain () - { in while(SCANF (" %d%d%d", &n, &m, &k)! =EOF) the { theb[0] =0; AboutLB = (int) sqrt (n); the the for(intI=1; i<=n; i++) the { +scanf ("%d", &b[i]); -B[i] ^= b[i-1]; the }Bayi the for(intI=0; i<m; i++) the { -scanf ("%d%d", &Q[I].L, &Q[I].R); -Q[i].id =i; the } the theSort (q, q+m, CMP); the - solve (); the the for(intI=0; i<m; i++) theprintf ("%i64d\n", Ans[i]);94 } the return 0; the}
Codeforces 617 E. XOR and favorite number