Educational Codeforces Round 12 E Beautiful Subarrays
先转换成异或前缀和,变成询问两个数异或≥k的方案数。
分治然后Trie树即可。
#include<cstdio>
#include<algorithm>
#define N 1000010
#define mid (l+r>>1)
#define ll long long
using namespace std;
int n,k,a[N];ll ans;
struct Trie
{
int next[N*][],tot,sum[N*];
void init()
{
for(int i=;i<=tot;i++)
next[i][]=next[i][]=sum[i]=;
tot=;
}
void add(int x)
{
int now=;
for(int i=;~i;i--)
{
int c=(x>>i)&;
if(!next[now][c])
next[now][c]=++tot;
now=next[now][c];
sum[now]++;
}
}
int query(int x)
{
int now=,res=;
for(int i=;~i;i--)
{
int c=(k>>i)&,p=(x>>i)&;
if(c==)res+=sum[next[now][!p]];
now=next[now][p^c];
if(!now)return res;
}
return res;
}
}t;
void solve(int l,int r)
{
if(l==r)return;
t.init();
for(int i=l;i<=mid;i++)
t.add(a[i]);
for(int i=mid+;i<=r;i++)
ans+=t.query(a[i]);
solve(l,mid);
solve(mid+,r);
}
int main()
{
scanf("%d%d",&n,&k);n++;k--;
for(int i=;i<=n;i++)
scanf("%d",&a[i]),a[i]^=a[i-];
solve(,n);
printf("%lld\n",ans);
}
Educational Codeforces Round 12 E Beautiful Subarrays的更多相关文章
- 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 trie求两异或值大于等于k对数
E. Beautiful Subarrays One day, ZS the Coder wrote down an array of integers a with elements a1, ...
- Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...
- [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 ...
随机推荐
- es_Linux
命令:echo 显示.印出 echo $PATH 通过 "su - vbird"" 这个指令来变换到 vbird身份 权限: rwx rwx rwx 以4 2 1数字表 ...
- WP8.1 RT 生命周期详解
应用状态关系转换图 根据此“应用状态关系转换图”.有以下: 三个状态: NotRunning:未运行 Running:运行中 Suspended:挂起 三个事件: A ...
- ODBC API简介
1. 数据类型: 通过SQLGetTypeInfo函数来获取ODBC 3.0支持的数据类型信息.由SQLGetTypeInfo返回的数据类型是数据源所支持的数据类型. SQLRETURN S ...
- CentOS 7.0,启用iptables防火墙
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...
- IDA插件栈字符串识别插件
该插件是一款可以自动识别栈上局部变量为字符串的插件,字符串形式如下,并自动的加上注释 如图:可以自动识别栈上的字符串 项目主 ...
- destoon公司搜索页面显示公司类型
首先找到前台模板文件:/template/default/company/search.htm 看到51行 {template 'list-company', 'tag'} 打开 /template/ ...
- IEnumerable和IQueryable和Linq的查询
IEnumerable和IEnumerable 1.IEnumerable查询必须在本地执行.并且执行查询前我们必须把所有的数据加载到本地.而且更多的时候.加载的数据有大量的数据是我们不需要的无效数据 ...
- java27
1:反射(理解) (1)类的加载及类加载器 (2)反射: 通过字节码文件对象,去使用成员变量,构造方法,成员方法 (3)反射的使用 A:通过反射获取构造方 ...
- nginx和rewrite的配置
测试ok 具体参见 http://www.ccvita.com/348.html
- linux 使用 nvidia 的 gpu
第一种方法: [Wizard@Wizard ~]$ nvidia-detect kmod-nvidiaOptimus hardware detected: An Intel display contr ...