先转换成异或前缀和,变成询问两个数异或≥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的更多相关文章

  1. Educational Codeforces Round 12 E. Beautiful Subarrays 字典树

    E. Beautiful Subarrays 题目连接: http://www.codeforces.com/contest/665/problem/E Description One day, ZS ...

  2. 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,   ...

  3. Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化

    链接:http://codeforces.com/contest/665/problem/E 题意:求规模为1e6数组中,连续子串xor值大于等于k值的子串数: 思路:xor为和模2的性质,所以先预处 ...

  4. [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 ...

  5. Educational Codeforces Round 63 D. Beautiful Array

    D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 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 ...

  7. Educational Codeforces Round 12 D. Simple Subset 最大团

    D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...

  8. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

  9. Educational Codeforces Round 12 B. Shopping 暴力

    B. Shopping 题目连接: http://www.codeforces.com/contest/665/problem/B Description Ayush is a cashier at ...

随机推荐

  1. Shell文件权限和脚本执行

    一.预备知识 1.shell的作用   2.常识 (1)Tab键自动补全   使用Terminal时,输入命令的前几个字母,敲tab会自动补全命令或文件名.目录等. 好处:操作速度更快:不容易出错: ...

  2. maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project web_nanchang

    maven打包成war时,报错:Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default- ...

  3. 理解Kalman滤波的使用

    Kalman滤波简介 Kalman滤波是一种线性滤波与预测方法,原文为:A New Approach to Linear Filtering and Prediction Problems.文章推导很 ...

  4. filterHTML

    function filterHTML(source) { return !source ? "" : source.replace(/]*>/g, "" ...

  5. PHP数组合并+与array_merge的区别分析 & 对多个数组合并去重技巧

    PHP中两个数组合并可以使用+或者array_merge,但之间还是有区别的,而且这些区别如果了解不清楚项目中会要命的! 主要区别是两个或者多个数组中如果出现相同键名,键名分为字符串或者数字,需要注意 ...

  6. C和指针 第七章 可变参数

    可变参数列表是通过stdarg.h内的宏来实现的: 类型 va_list 三个宏: va_start va_arg va_end 我们可以声明一个va_list变量,与这三个宏配合使用. 可变参数必须 ...

  7. TCP/IP三次握手和HTTP过程

    1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络数据的传输建立在"无差别&qu ...

  8. MongoDB_C_Driver使用教程(2)高级连接

    高级连接(Advanced Connection) 以下指南包含MongoDB配置的特定类型的信息. 简单的连接到独立服务器的示例,请参考MongoDB_C_Dirver使用教程. 要连接到启用身份验 ...

  9. JQuery mobile中按钮自定义属性的改变

    1..ui-mobile-viewport是jquery mobile默认给body加的class,这样的话包含选择符优先级高一点 <style> .ui-mobile-viewport ...

  10. 基于winner 滤波平稳降噪效果

    https://en.wikipedia.org/wiki/Wiener_filter Wiener filter solutions The Wiener filter problem has so ...