Beautiful Subarrays
time limit per test

3 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an.

A subarray of the array a is a sequence al,  al  +  1,  ...,  ar for some integers (l,  r) such that 1  ≤  l  ≤  r  ≤  n. ZS the Coder thinks that a subarray of a is beautiful if the bitwise xor of all the elements in the subarray is at least k.

Help ZS the Coder find the number of beautiful subarrays of a!

Input

The first line contains two integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 109) — the number of elements in the array a and the value of the parameter k.

The second line contains n integers ai (0 ≤ ai ≤ 109) — the elements of the array a.

Output

Print the only integer c — the number of beautiful subarrays of the array a.

Examples
input
  1. 3 1
    1 2 3
output
  1. 5
input
  1. 3 2
    1 2 3
output
  1. 3
input
  1. 3 3
    1 2 3
output
  1. 2
    分析:trie树,保留每个前缀再异或即可;
    代码:
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cstring>
  8. #include <string>
  9. #include <set>
  10. #include <map>
  11. #include <queue>
  12. #include <stack>
  13. #include <vector>
  14. #include <list>
  15. #define rep(i,m,n) for(i=m;i<=n;i++)
  16. #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
  17. #define mod 1000000007
  18. #define inf 0x3f3f3f3f
  19. #define vi vector<int>
  20. #define pb push_back
  21. #define mp make_pair
  22. #define fi first
  23. #define se second
  24. #define ll long long
  25. #define pi acos(-1.0)
  26. #define pii pair<int,int>
  27. #define Lson L, mid, rt<<1
  28. #define Rson mid+1, R, rt<<1|1
  29. const int maxn=2e7+;
  30. using namespace std;
  31. ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
  32. ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
  33. inline ll read()
  34. {
  35. ll x=;int f=;char ch=getchar();
  36. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  37. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  38. return x*f;
  39. }
  40. int n,m,k,t,ch[maxn][],sz[maxn],tot;
  41. ll ans;
  42. void insert(int p)
  43. {
  44. int now=;
  45. for(int i=;i>=;i--)
  46. {
  47. int q=(p>>i)&;
  48. if(!ch[now][q])ch[now][q]=++tot;
  49. now=ch[now][q],sz[now]++;
  50. }
  51. }
  52. ll get(int p)
  53. {
  54. int now=;
  55. ll ans=;
  56. for(int i=;i>=;i--)
  57. {
  58. int q=(p>>i)&^,t=(m>>i)&;
  59. if(!t)ans+=sz[ch[now][q]],now=ch[now][q^];
  60. else now=ch[now][q];
  61. if(!now)return ans;
  62. }
  63. return ans+sz[now];
  64. }
  65. int main()
  66. {
  67. int i,j;
  68. insert();
  69. scanf("%d%d",&n,&m);
  70. while(n--)
  71. {
  72. scanf("%d",&j),k^=j;
  73. ans+=get(k);
  74. insert(k);
  75. }
  76. printf("%lld\n",ans);
  77. //system("Pause");
  78. return ;
  79. }

Beautiful Subarrays的更多相关文章

  1. Educational Codeforces Round 12 E. Beautiful Subarrays 字典树

    E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...

  2. codeforces 665E E. Beautiful Subarrays(trie树)

    题目链接: E. Beautiful Subarrays time limit per test 3 seconds memory limit per test 512 megabytes input ...

  3. 【Codeforces】665E Beautiful Subarrays

    E. Beautiful Subarrays time limit per test: 3 seconds memory limit per test: 512 megabytes input: st ...

  4. Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数

    E. Beautiful Subarrays   One day, ZS the Coder wrote down an array of integers a with elements a1,   ...

  5. Educational Codeforces Round 12 E Beautiful Subarrays

    先转换成异或前缀和,变成询问两个数异或≥k的方案数. 分治然后Trie树即可. #include<cstdio> #include<algorithm> #define N 1 ...

  6. Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化

    链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...

  7. codeforces 665E Beautiful Subarrays

    题目链接 给一个数列, 让你找出异或结果大于等于k的子序列的个数. 因为任意一段序列的异或值都可以用前缀异或和来表示, 所以我们先求出前缀异或和. 我们考虑字典树, 对于每一个前缀sum, 我们先查询 ...

  8. Codeforces 665E. Beautiful Subarrays (字典树)

    题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意 ...

  9. E. Beautiful Subarrays 字典树

    http://codeforces.com/contest/665/problem/E 给定一个序列,问其中有多少个区间,所有数字异或起来 >= k 看到异或,就应该想到异或的性质,A^B^B ...

随机推荐

  1. HDU - 1045 Fire Net(搜索)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...

  2. web.config中httpModules和Modules的区别

    最近用到了mvc的 Modules管道时,发现web.config中有两个modules 1.system.web节点下的httpModules 2.system.webServer节点下的modul ...

  3. jquery-图片轮播(新手请大神指教一下)

    这是我刚学jquery写的,感觉效果不是很好. #scrollPics{ height: 330px; width: 980px; margin-bottom: 10px; overflow: hid ...

  4. linux查看内核版本

    cat /proc/version 或者 cat /etc/issue 或者 uname -a

  5. js第一天 innerHTML和value 的区别

    innerHTML在JS是双向功能:获取对象的内容 或 向对象插入内容:如:<div id="aa">这是内容</div> ,我们可以通过 document ...

  6. linux文件权限赋值

    1修改权限     命令:chmod (change mode)     功能:改变文件的读写和执行权限.有符号法和八进制数字法.     选项:(1)符号法:   命令格式:chmod {u|g|o ...

  7. MySQL主从配置【转载】

    1.主从服务器分别作以下操作:  1.1.版本一致  1.2.初始化表,并在后台启动mysql  1.3.修改root的密码 2.修改主服务器master:   #vi /etc/my.cnf     ...

  8. 多项目中SVN权限管理精辟解析

    本节和大家讨论一下多项目SVN权限管理,主要包括建立版本库,修改版本库配置文件,配置允许访问的用户,设置用户访问权限.下面我们就来看一下SVN权限管理.svn权限管理svn的权限管理涉及到一下文件:p ...

  9. Qt 学习之路 2(84):Repeater

    前面的章节我 们介绍过模型视图.这是一种数据和显示相分离的技术,在 Qt 中有着非常重要的地位.在 QtQuick 中,数据和显示的分离同样也是利用这种"模型-视图"技术实现的.对 ...

  10. spring 基于XML和注解的两种事务配置方式

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...