E. Beautiful Subarrays

题目连接:

http://www.codeforces.com/contest/665/problem/E

Description

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.

Sample Input

3 1

1 2 3

Sample Output

5

Hint

题意

问你有多少个区间,异或起来大于等于k

题解:

显然求个前缀和之后,就等于有多少对数异或起来大于等于k了

这个玩意儿我们每次暴力爬字典树就好了

当k这一位等于0的时候,我们可以直接加上另外一边1的子树大小,因为爬那边之后,我怎么爬都是大于等于k的

然后就这样直接暴力莽一波就好了~

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e7+6;
struct Tri
{
int ch[maxn][2];
int sz[maxn];
int tot;
void init()
{
memset(ch,0,sizeof(ch));
memset(sz,0,sizeof(sz));
tot=2;
}
void insert(int x)
{
int u=1;
for(int i=30;i>=0;i--)
{
int p = (x>>i)&1;
if(!ch[u][p])ch[u][p]=tot++;
sz[u]++;
u=ch[u][p];
}
sz[u]++;
}
int get(int x,int y)
{
int u=1;
long long ans = 0;
for(int i=30;i>=0;i--)
{
int p = (x>>i)&1^1;
int q = (y>>i)&1;
if(q==0)ans+=sz[ch[u][p]],u=ch[u][p^1];
else u=ch[u][p];
}
return ans+sz[u];
}
}T;
int main()
{
T.init();
int n,k;
scanf("%d%d",&n,&k);
int pre = 0;
long long ans = 0;
T.insert(0);
for(int i=1;i<=n;i++)
{
int x;scanf("%d",&x);
pre^=x;
ans+=T.get(pre,k);
T.insert(pre);
}
cout<<ans<<endl;
}

Educational Codeforces Round 12 E. Beautiful Subarrays 字典树的更多相关文章

  1. 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,   ...

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

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

  3. Educational Codeforces Round 12 E Beautiful Subarrays

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

  4. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

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

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

  6. E. Beautiful Subarrays 字典树

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

  7. Educational Codeforces Round 63 D. Beautiful Array

    D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Educational Codeforces Round 12 F. Four Divisors 求小于x的素数个数(待解决)

    F. Four Divisors 题目连接: http://www.codeforces.com/contest/665/problem/F Description If an integer a i ...

  9. Educational Codeforces Round 12 D. Simple Subset 最大团

    D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...

随机推荐

  1. linux设置时区同步时间

    linux设置时区同步时间 一.运行tzselect sudo tzselect 在这里我们选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing) 如图:   二.复制文件 ...

  2. 选中一行并且选中该行的radio

    $("tr").bind("click",function(){ $("input:radio").attr("checked&q ...

  3. Java Web Project Problems

    A: 项目红叉 1. 检验 Java Builder  Path 2. 检查 Projects Facets 3. 查看 Targets Runtimes B:项目红感叹号 1. 查看问题栏 Prob ...

  4. MAC 文件被锁定

    从windows拷贝到MAC的文件,有时候会被锁定.右键-简介-已锁定也是灰色的,无法取消: xattr -l 文件名 xattr -d com.apple.FinderInfo 文件名

  5. Netty并发优化之ExecutionHandler

    上文<Netty框架入门>说到:如果业务处理handler耗时长,将严重影响可支持的并发数. 针对这一问题,经过学习,发现了可以使用ExecutionHandler来优化. 先来回顾一下没 ...

  6. Nginx源码分析-ngx_module_s结构体

    该结构体是整个Nginx模块化架构最基本的数据结构体.它描述了Nginx程序中一个模块应该包括的基本属性,在tengine/src/core/ngx_conf_file.h中定义了该结构体 struc ...

  7. 1、CentOS 6 安装GitLab

    1.安装和配置必需的依赖项 在CentOS上将系统防火墙打开HTTP和SSH访问. sudo yum install -y curl policycoreutils-python openssh-se ...

  8. Bootstrap开发模板

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  9. HTML+CSS图文排版

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  10. HDU 1043 Eight(反向BFS+打表+康托展开)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 题目大意:传统八数码问题 解题思路:就是从“12345678x”这个终点状态开始反向BFS,将各 ...