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 ...
随机推荐
- 仿QQ浏览器mac版官网主页 html+css3特效
这是一款超酷的CSS3动态背景动画特效,CSS3仿QQ浏览器官网彗星动画背景特效. 在线演示本地下载
- Android Drawable之getIntrinsicWidth()和getIntrinsicHeight()
在Android的开发中,凡是需要画图的地方大都离不开类Drawable.Android的官方文档中介绍这个类就是被设计用来表示可以被画的东西.A Drawable is a ge ...
- LCA 离线的Tarjan算法 poj1330 hdu2586
LCA问题有好几种做法,用到(tarjan)图拉算法的就有3种.具体可以看邝斌的博客.http://www.cnblogs.com/kuangbin/category/415390.html 几天的学 ...
- 四.Windows I/O模型之重叠IO(overlapped)模型
1.适用于除Windows CE之外的各种Windows平台.在使用这个模型之前应该确保该系统安装了Winsock2.重叠模型的基本设计原理是使用一个重叠的数据结构,一次投递一个或多个Winsock ...
- C# 遍历对象下的 属性
foreach (System.Reflection.PropertyInfo p in users.GetType().GetProperties()) { var xx = p.Name; var ...
- 使用序列号激活优动漫PAINT(附激活码)
优动漫PAINT是一款功能强大的动漫绘图软件,简单的中文界面和丰富的笔刷操纵,再次为设计工作者带来非一般的感受!最近,有不少小伙伴提出这样的疑问:购买安装优动漫PAINT之后,不知道如何激活,在哪里输 ...
- Webstorm 破解2017.1 for Mac
废话不多说,改了去年分享2016版本的文章,给同学们带来2017.1版本的Mac版本.(win版本网上很多,我这里就不贴出来了). 1.去官仿下载最新的版本 https://www.jetbrain ...
- Binary Agents FreeCodeCamp
function binaryAgent(str) { var arr = str.split(" "); var newStr = ""; for(var i ...
- matlab学习创建变量定义函数
定义变量a,b,c,计算输出d >> a=-3;b=2;c=5;>> d=(a^2+b)/c;>> d=(a^2+b)/c d = 2.2000 系统默认变量 a ...
- 对于开启tomcat后无法登陆index.xml的新解决方法
首先这个问题是针对tomcat路径什么的都正确,但是就是无法登陆index.xml 如上图,之前忘了写<packaging>war</packaging>所以无法登陆index ...