Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri 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 ai, ai + 1, ..., ajis equal to k.

Input

The first line of the input contains integers nm and k (1 ≤ n, m ≤ 100 000, 0 ≤ k ≤ 1 000 000) — the length of the array, the number of queries and Bob's favorite number respectively.

The second line contains n integers ai (0 ≤ ai ≤ 1 000 000) — Bob's array.

Then m lines follow. The i-th line contains integers li and ri (1 ≤ li ≤ ri ≤ n) — the parameters of the i-th query.

Output

Print m lines, answer the queries in the order they appear in the input.

Examples

Input
  1. 6 2 3
    1 2 1 1 0 3
    1 6
    3 5
Output
  1. 7
    0
Input
  1. 5 3 1
    1 1 1 1 1
    1 5
    2 4
    1 3
Output
  1. 9
    4
    4
  2.  
  3. 题意:
    询问区间内异或和刚好为k的字段个数。
    思路:
    莫队+前缀和。
    这个前缀和比较套路,用的是前缀异或和。
    字段【l,r】的异或和就是pre[r]^pre[l-1],
    这种情况下我们在莫队的过程中记录lrpre[i]出现的次数,就可以完成更新了。
  4.  
  5. 注意当L<q[i].l时,要先让记录per[L]出现次数的个数减一。
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<stack>
  5. #include<queue>
  6. #include<map>
  7. #include<set>
  8. #include<cstdio>
  9. #include<cstring>
  10. #include<cmath>
  11. #include<ctime>
  12. #define fuck(x) cout<<#x<<" = "<<x<<endl;
  13. #define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
  14. #define ls (t<<1)
  15. #define rs ((t<<1)+1)
  16. using namespace std;
  17. typedef long long ll;
  18. typedef unsigned long long ull;
  19. const int maxn = ;
  20. const int maxm = ;
  21. const int inf = 2.1e9;
  22. const ll Inf = ;
  23. const int mod = ;
  24. const double eps = 1e-;
  25. const double pi = acos(-);
  26. int num[maxm*],pre[maxn],a[maxn];
  27.  
  28. struct node{
  29. int l,r;
  30. int id;
  31. }q[maxn];
  32. ll ans[maxn];
  33. ll anss;
  34. int block;
  35.  
  36. bool cmp(node a,node b){
  37. if(a.l/block!=b.l/block){return a.l<b.l;}
  38. return a.r<b.r;
  39. }
  40.  
  41. int main()
  42. {
  43. int n,m,k;
  44. scanf("%d%d%d",&n,&m,&k);
  45. for(int i=;i<=n;i++){
  46. scanf("%d",&a[i]);
  47. pre[i]=pre[i-]^a[i];
  48. }
  49.  
  50. block=sqrt(n);
  51.  
  52. for(int i=;i<=m;i++){
  53. scanf("%d%d",&q[i].l,&q[i].r);
  54. q[i].id=i;
  55. }
  56.  
  57. sort(q+,q++m,cmp);
  58. int L=,R=;
  59. anss=;
  60. num[]=;
  61. for(int i=;i<=m;i++){
  62. while(L<q[i].l){
  63. int t=k^pre[L-];
  64. num[pre[L-]]--;///注意语句顺序
  65. anss-=num[t];
  66. L++;
  67. }
  68. while(R>q[i].r){
  69. int t=k^pre[R];
  70. num[pre[R]]--;
  71. anss-=num[t];
  72. R--;
  73. }
  74. while(L>q[i].l){
  75. L--;
  76. int t=k^pre[L-];
  77. anss+=num[t];
  78. num[pre[L-]]++;
  79. }
  80. while(R<q[i].r){
  81. R++;
  82. int t=k^pre[R];
  83. anss+=num[t];
  84. num[pre[R]]++;
  85. }
  86. ans[q[i].id]=anss;
  87. }
  88. for(int i=;i<=m;i++){
  89. printf("%lld\n",ans[i]);
  90. }
  91. return ;
  92. }

CodeForces - 617E XOR and Favorite Number (莫队+前缀和)的更多相关文章

  1. CodeForces - 617E XOR and Favorite Number 莫队算法

    https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry,  问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...

  2. Codeforces 617E XOR and Favorite Number莫队

    http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...

  3. codeforces 617E. XOR and Favorite Number 莫队

    题目链接 给n个数, m个询问, 每次询问问你[l, r]区间内有多少对(i, j), 使得a[i]^a[i+1]^......^a[j]结果为k. 维护一个前缀异或值就可以了. 要注意的是 区间[l ...

  4. CODEFORCES 340 XOR and Favorite Number 莫队模板题

    原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries ...

  5. Codeforces Round #340 (Div. 2) E 莫队+前缀异或和

    E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  6. codeforces 617E E. XOR and Favorite Number(莫队算法)

    题目链接: E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes i ...

  7. Codeforces 617E XOR and Favorite Number(莫队算法)

    题目大概说给一个序列,多次询问区间异或和为k的连续子序列有多少个. 莫队算法,利用异或的性质,通过前缀和求区间和,先处理出序列各个前缀和,然后每次区间转移时维护i以及i-1前缀和为某数的个数并增加或减 ...

  8. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

    E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...

  9. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 ...

随机推荐

  1. php刷新当前页面,js刷新页面

    echo "<script language=JavaScript> location.replace(location.href);</script>"; ...

  2. @codeforces - 717A@ Festival Organization

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 一个长度为 n 的 01 序列是好的,当且仅当该序列任意两个 0 ...

  3. Android实战:手把手实现“捧腹网”APP(三)-----UI实现,逻辑实现

    Android实战:手把手实现"捧腹网"APP(一)-–捧腹网网页分析.数据获取 Android实战:手把手实现"捧腹网"APP(二)-–捧腹APP原型设计.实 ...

  4. GitOps:Kubernetes多集群环境下的高效CICD实践

    为了解决传统应用升级缓慢.架构臃肿.不能快速迭代.故障不能快速定位.问题无法快速解决等问题,云原生这一概念横空出世.云原生可以改进应用开发的效率,改变企业的组织结构,甚至会在文化层面上直接影响一个公司 ...

  5. Nacos Committer 张龙:Nacos Sync 的设计原理和规划

    图:Nacos Meetup @杭州 与你同行,抬头便是星空. 本文整理自Nacos Committer 张龙的现场分享,阿里巴巴中间件受权发布. 随着 Nacos 1.0.0 稳定版的发布,越来越多 ...

  6. oracle函数 current_timestamp

    [功能]:以timestamp with time zone数据类型返回当前会话时区中的当前日期 [参数]:没有参数,没有括号 [返回]:日期 [示例]select current_timestamp ...

  7. OpenStack Nova启动实例流程

    1.概述 启动一个新的实例,会涉及到OpenStack Nova中的多个组件: API服务器,接收用户端的请求,并且将其传递给云控制器. 云控制器,处理计算节点.网络控制器.API服务器和调度器之前的 ...

  8. 初识 Knative: 跨平台的 Serverless 编排框架

    Knative 是什么 Knative 是 Google 在 2018 的 Google Cloud Next 大会上发布的一款基于 Kubernetes 的 Serverless 框架.Knativ ...

  9. selenium webdriver学习(九)------------如何操作cookies(转)

    selenium webdriver学习(九)------------如何操作cookies 博客分类: Selenium-webdriver   Web 测试中我们经常会接触到Cookies,一个C ...

  10. behavior planning——11 create a cost function speed penalty

    A  key part of getting transitions to happen when we want  them to is the design of reasonable cost ...