Codeforces 617 E. XOR and favorite number

Source: Internet
Author: User

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", &AMP;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

Related Article

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.