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 ...
随机推荐
- thinkphp 3.2与phpexcel
thinkphp版本:3.2 1.在http://phpexcel.codeplex.com/下载最新PHPExcel 2.把Classes目录下的文件(PHPExcel.php和PHPExcel文件 ...
- PHP变量入门教程(4)PHP 的外部变量
PHP 的外部变量 HTML 表单(GET 和 POST) 当一个表单体交给 PHP 脚本时,表单中的信息会自动在脚本中可用.有很多方法访问此信息,例如: 一个简单的 HTML 表单 <form ...
- ASP.NET Web API学习 (一)
开发环境:win10,使用VS2015社区版和SQLSERVER2012开发 1.打开VS2015应用程序,点击左上角按钮:文件--新建--项目,弹出窗口中选择ASP.NET Web应用程序, 2.点 ...
- 第七届山东省ACM省赛
激动人心的省赛终于结束了…平静下来再回头看真的感觉一波三折…先是赛前毫无预兆的查出突发性耳聋…伴随而来的就是左耳听力下降.轻微耳鸣.极个别情况下的头晕…不过这都还好,毕竟药物可以恢复…热身赛只过了一道 ...
- 兼容IE8以下浏览器input表单属性placeholder不能智能提示功能
当前很多表单提示使用了表单属性placeholder,可这属性不兼容IE8以下的浏览器,我自己写了一个兼容处理js // 兼容IE8以下浏览器input不能智能提示功能 if(navigator.ap ...
- Spring配置文件中使用表达式
在配置文件中使用Java类 <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieR ...
- MySQL5.6 PERFORMANCE_SCHEMA 说明
背景: MySQL 5.5开始新增一个数据库:PERFORMANCE_SCHEMA,主要用于收集数据库服务器性能参数.并且库里表的存储引擎均为PERFORMANCE_SCHEMA,而用户是不能创建存储 ...
- Unity 3D 我来了
- ReactiveCocoa学习
ReactiveCocoa常见类 6.1RACSiganl:信号类,一般表示将来有数据传递,只要有数据改变,信号内部接收到数据,就会马上发出数据. 注意: 信号类(RACSiganl),只是表示当数据 ...
- .NET LINQ 聚合操作
聚合操作 聚合运算从值集合计算单个值. 从一个月的日温度值计算日平均温度就是聚合运算的一个示例. 方法 方法名 说明 C# 查询表达式语法 Visual Basic 查询表达式语法 更多信息 ...