先转换成异或前缀和,变成询问两个数异或≥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. Java Web笔记之Servlet(1)

    今天在学习Servlet时,使用浏览器显示的网页效果与预期的有差异,仔细查找发现实<!DOCTYPE>声明的问题,截图如下: 代码如下: package secondServlet; im ...

  2. [Head First设计模式]抢票中的设计模式——代理模式

    系列文章 [Head First设计模式]山西面馆中的设计模式——装饰者模式 [Head First设计模式]山西面馆中的设计模式——观察者模式 [Head First设计模式]山西面馆中的设计模式— ...

  3. 关于Hibernate5.x的那点事

    1.如果采用程序建表: 4.x版本: Configuration cfg = new Configuration().configure(); SchemaExport se = new Schema ...

  4. thinkphp自定义标签库

    thinkphp ~ php中 的类, 的成员变量, 本身是没有类型说明的, 那么我怎么知道它的类型呢? 或初始值呢? 通常在类定义中, 如果能给一个初始值的(对于已知简单类型的),最好给一个初始值, ...

  5. Response.End()出现ThreadAbortException 异常

    A. 如果使用 Response.End.Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAbortException 异常.异常内容:由于代码已经过 ...

  6. C# *= 运算顺序

    a *= a + b *c; 不管等号右边有没有括号,总是先算右边: 即等价于 a = a *(a + b*c); using System; using System.Collections.Gen ...

  7. redis集群之REDIS CLUSTER

    redis集群之REDIS CLUSTER 时间 2016-04-11 17:05:00  NoSQL_博客园 原文  http://www.cnblogs.com/zhanchenjin/p/537 ...

  8. [Linux]系统调用理解(2)

    本文介绍了Linux下的进程概念,并着重讲解了与Linux进程管理相关的4个重要系统调用getpid,fork,exit和_exit,辅助一些例程说明了它们的特点和使用方法. 关于进程的一些必要知识 ...

  9. c++ 虚函数和纯虚函数

    在你设计一个基类的时候,如果发现一个函数需要在派生类里有不同的表现,那么它就应该是虚的.从设计的角度讲,出现在基类中的虚函数是接口,出现在派生类中的虚函数是接口的具体实现.通过这样的方法,就可以将对象 ...

  10. laravel安装笔记

    一.安装composer 安装之前将\php\php.ini文件中的php_openssl.dll扩展库开启,否则composer在安装过程中会出现错误提示. (我在安装过程中发现apache目录下的 ...