Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数
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!
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.
Print the only integer c — the number of beautiful subarrays of the array a.
3 1
1 2 3
5
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e7+;
struct Tri
{
int ch[maxn][];
int sz[maxn];
int tot;
void init()
{
memset(ch,,sizeof(ch));
memset(sz,,sizeof(sz));
tot=;
}
void insert(int x)
{
int u=;sz[u]++;
for(int i=;i>=;i--)
{
int p = (x>>i)&;
if(!ch[u][p])ch[u][p]=tot++;
u=ch[u][p]; sz[u]++;
}
}
int get(int x,int y)
{
int u=;
long long ans = ;
for(int i=;i>=;i--)
{
int p = (x>>i)&^;
int q = (y>>i)&;
if(q==)ans+=sz[ch[u][p]],u=ch[u][p^];
else u=ch[u][p];
if(u==) return ans;
}
return ans+sz[u];
}
}T;
int main()
{
T.init();
int n,k;
scanf("%d%d",&n,&k);
int pre = ;
long long ans = ;
T.insert();
for(int i=;i<=n;i++)
{
int x;scanf("%d",&x);
pre^=x;
ans+=T.get(pre,k);
T.insert(pre);
}
cout<<ans<<endl;
return ;
}
Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数的更多相关文章
- Educational Codeforces Round 12 E. Beautiful Subarrays 字典树
E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- Educational Codeforces Round 12 E Beautiful Subarrays
先转换成异或前缀和,变成询问两个数异或≥k的方案数. 分治然后Trie树即可. #include<cstdio> #include<algorithm> #define N 1 ...
- [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 ...
- Educational Codeforces Round 63 D. Beautiful Array
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
- Educational Codeforces Round 12 D. Simple Subset 最大团
D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...
- Educational Codeforces Round 12 C. Simple Strings 贪心
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...
- Educational Codeforces Round 12 B. Shopping 暴力
B. Shopping 题目连接: http://www.codeforces.com/contest/665/problem/B Description Ayush is a cashier at ...
随机推荐
- BZOJ-4706 B君的多边形 OEIS
题面 题意:有一个正n多边形,我们要连接一些对角线,把这个多边形分成若干个区域,要求连接的对角线不能相交,每个点可以连出也可以不连出对角线,即最终不要求所有区域均为三角形,问总方案数mod (10^9 ...
- NOIP2013T1 转圈游戏 快速幂
描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置, --, 依此 ...
- 关于api接口文档RAP和swagger
前言: 在之前的项目中用了将近一年的RAP,RAP是由阿里开源出来的,非常好用.github地址:https://github.com/thx/RAP. 当初在用此工具时,项目成员需要在接口文档在所改 ...
- Windows下配置SVN服务器
2013-09-03 21:40:34 1. 下载安装svn软件 1.1 服务端svn 下载地址:http://subversion.apache.org/packages.html 默认安装路径:D ...
- Hadoop MapReduce编程 API入门系列之FOF(Fund of Fund)(二十三)
不多说,直接上代码. 代码 package zhouls.bigdata.myMapReduce.friend; import org.apache.hadoop.io.Text; public cl ...
- 6.Renderer Window
渲染是实时的,所见即所得.同时还可以输出一些统计信息. Pixel Snoop:获取颜色值,同时把该值复制到剪贴板,主要用户是获取颜色值 Wireframe:开启后可以查看3D节点图形骨架 Stati ...
- js中国各大城市快速选择代码
js中国各大城市快速选择插件 在线演示本地下载
- 学习环境搭建1——安装python
操作系统:windows7 64bit 下载地址python :https://www.python.org/ 下载Windows x86-64 executable installer 安 ...
- C#读取EXCEL 并输出到文本框
#region 加载数据到DataGraidView private void button1_Click(object sender, EventArgs e) { string excelPath ...
- Python基础:条件判断 &&循环
1:条件判断 2:循环 2.1:for 2.2 while 小结: continue :跳出本次循环 进行下次循环, break :结束循环体.