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 ...
随机推荐
- php mktime和strtotime
本文章来给各位同学介绍一下利用php用strtotime或mktime指定日期数据(本周,上周,本月,上月,本季度)实例,希望对各位同学会有所帮助呀. strtotime定义和用法 strtotime ...
- 从Android源码分析View绘制
在开发过程中,我们常常会来自定义View.它是用户交互组件的基本组成部分,负责展示图像和处理事件,通常被当做自定义组件的基类继承.那么今天就通过源码来仔细分析一下View是如何被创建以及在绘制过程中发 ...
- JS和PHP之间以JSON格式传输
Json是一种的轻量级文本数据交换格式.它独立于编程语言,可以用于在不用的编程语言之间进行数据的交互. 下面简单例举二个使用JSON进行数据通信的例子. 第一个例子: //Javascript以aja ...
- oc懒加载 & swift lazy
oc的懒加载依赖于属性的双重属性的函数属性部分. 懒加载的本质是执行get函数. swift的lazy,理论上与此类似. 编译器优化时可能对初始化块进行了保存. 懒加载的本质是延迟执行. 只要是执行, ...
- ZBrush的双十一来了,然鹅...
不管是“光棍节”还是“剁手节” 似乎和我都没有什么关系 事实证明,我错了 今早竟然有不识趣的人发红包祝我单身快乐 纳尼,这是唱的哪一出? 我能直接怼回去,说不领么? 但好像又不是我的风格 哎,一个红包 ...
- 企业级任务调度框架Quartz(6) 任务调度器(Scheduler)
前序: 我们已经在前面的内容能里看到了,我们用 Scheduler 来管理我们的 Job:创建并关联触发器以使 Job 能被触发执行:以及如可选择 calendar 为给定的时程安排提供更多 ...
- 洛谷P1993 小K的农场_差分约束_dfs跑SPFA
Code: #include<cstdio> #include<queue> using namespace std; const int N=10000+233; const ...
- loadrunner笔记----好记性不如烂笔头
1.Loadrunner主要由Vugen,Controller和Analyais3部分组成 2.简述描述集合点和集合点函数 集合点可以同步虚拟用户,以便能在同一时刻执行任务,集合点函数lr_rende ...
- android的listview的addheaderView总是出现空指针的错误
android的listview的addheaderView总是出现空指针的错误, 网上的处理方法如下: // This doesn't work... nullPointerException Li ...
- CF528D Fuzzy Search (生成函数+FFT)
题目传送门 题目大意:给你两个只包含A,G,C,T的字符串$S$,$T$,$S$长$T$短,按照如下图方式匹配 解释不明白直接上图 能容错的距离不超过$K$,求能$T$被匹配上的次数 $S$串同一个位 ...