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 ...
随机推荐
- ImageView的常用属性
ImageView的一些常用属性,并且这些属性都有与之对应的getter.setter方法: android:adjustViewBounds:设置ImageView是否调整自己的边界来保持所显示图片 ...
- Django基础,Day9 - 静态文件目录与路径设置说明(eg. images, JavaScript, CSS)
静态文件路径设置官方说明 1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS. 2. In ...
- noip2015 运输计划
描述 公元 2044 年,人类进入了宇宙纪元.L 国有 nn 个星球,还有 n−1n−1 条双向航道,每条航道建立在两个星球之间,这 n−1n−1 条 航道连通了 L 国的所有星球. 小 P 掌管一家 ...
- PHP header函数使用大全
PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://52php.cnbl ...
- 【Alpha版本】 第二天 11.8
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 我要招聘详情的展示 注册界面的实现 填写招聘时用户填写各个日期到可 ...
- js求时间差
var date1=new Date(); //开始时间 alert("aa"); var date2=new Date(); //结束时间 var date3=date2 ...
- PHPExcel yii2 加载使用
除了用composer 包管理组件的方式外 我们还可以使用 直接最原始的加载方式---超级简单 1.PHPExcel上下载最新的PHPExcel http://phpexcel.codeplex.co ...
- ubuntu和centos安装RRDTool——cacti前置技能
Installing Pre-Requisites Note that RRDTool 1.0.x versions included all dependancies, but 1.2.x vers ...
- java5
1:final关键字(掌握) (1)是最终的意思,可以修饰类,方法,变量. (2)特点: A:它修饰的类,不能被继承. B:它修饰的方法,不能被重写. C:它修饰的变量,是一个常量. (3)面试相关: ...
- Shell 编程 : 数值,字符,字符串
数值运算命令 expr 命令 expr expression expression 是由字符串 以及 运算符所组成的,每一个字符串或说运算符之间必须用空格隔开, 运算符的优 ...