题目链接:

E. Beautiful Subarrays

time limit per test

3 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an.

A subarray of the array a is a sequence al,  al  +  1,  ...,  ar for some integers (l,  r) such that 1  ≤  l  ≤  r  ≤  n. ZS the Coder thinks that a subarray of a is beautiful if the bitwise xor of all the elements in the subarray is at least k.

Help ZS the Coder find the number of beautiful subarrays of a!

Input
 

The first line contains two integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 109) — the number of elements in the array a and the value of the parameter k.

The second line contains n integers ai (0 ≤ ai ≤ 109) — the elements of the array a.

Output
 

Print the only integer c — the number of beautiful subarrays of the array a.

Examples
 
input
3 1
1 2 3
output
5
input
3 2
1 2 3
output
3
input
3 3
1 2 3
output
2

题意:

给n个数,问有多少对数满足a[i]^a[i+1]^...^a[j]>=k;

思路:

处理出前缀异或和,再用trie树搞;

AC代码
#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(b));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=2e7+;
int n,k,cnt=;
int tree[N][],val[N];
void add_num(int num)
{
int x=;
for(int i=;i>=;i--)
{
int y=(num>>i)&;
if(!tree[x][y])tree[x][y]=cnt++;
val[x]++;
x=tree[x][y];
}
val[x]++;
}
LL get_ans(int num,int fy)
{
LL sum=;
int x=;
for(int i=;i>=;i--)
{
int y=(fy>>i)&;
int fx=(num>>i)&^;
if(y==)
{
sum+=(LL)val[tree[x][fx]];
x=tree[x][fx^];
}
else x=tree[x][fx];
}
return sum+(LL)val[x];
}
int main()
{
scanf("%d%d",&n,&k);
int pre=;
LL ans=;
add_num();
Riep(n)
{
int a;
scanf("%d",&a);
pre^=a;
ans+=(LL)get_ans(pre,k);
add_num(pre);
}
printf("%I64d\n",ans); return ;
}

codeforces 665E E. Beautiful Subarrays(trie树)的更多相关文章

  1. Codeforces 633C Spy Syndrome 2 | Trie树裸题

    Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...

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

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

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

  4. Codeforces 852G Bathroom terminal 【Trie树】

    <题目链接> 题目大意: 现在给定出n个字符串,并且进行m此询问,每次询问给出一个匹配串,每次询问都给出该匹配串能够匹配的字符串个数(题目只出现字符'a'~'e').'?'可以看成任意字符 ...

  5. Codeforces 665E. Beautiful Subarrays (字典树)

    题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意 ...

  6. Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组

    题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...

  7. E. Beautiful Subarrays 字典树

    http://codeforces.com/contest/665/problem/E 给定一个序列,问其中有多少个区间,所有数字异或起来 >= k 看到异或,就应该想到异或的性质,A^B^B ...

  8. Codeforces 1464F - My Beautiful Madness(树的直径)

    Codeforces 题面传送门 & 洛谷题面传送门 树上数据结构大杂烩(?) 首先考虑什么样的点能够在所有路径的 \(d\) 邻居的交集内.显然如果一个点在一条路径的 \(d\) 邻居内则必 ...

  9. 【Codeforces】665E Beautiful Subarrays

    E. Beautiful Subarrays time limit per test: 3 seconds memory limit per test: 512 megabytes input: st ...

随机推荐

  1. Yii2之创建定时任务

    yii开发的项目需要使用定时任务其实也可以使用一些单独的脚本文件来完成,但若是定时任务代码中需要使用到项目中的一些类,特别是需要使用应用对象Yii::$app的时候,单独的脚本想要完成就比较麻烦了.这 ...

  2. python--输出自己需要的字符串连接的的方式

    python中有很多字符串连接方式,今天在写代码,顺便总结一下,从最原始的字符串连接方式到字符串列表连接,大家感受下: 最原始的字符串连接方式:str1 + str2 python 新字符串连接语法: ...

  3. ubuntu下用webbench做网站压力测试

    安装依赖 exuberant-ctags sudo apt-get install exuberant-ctags 下载源码并安装 wget http://blog.s135.com/soft/lin ...

  4. Codeforces 665C Simple Strings【暴力,贪心】

    题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚 ...

  5. delphi函数大全

    delphi函数大全Abort                 函数    引起放弃的意外处理Abs                   函数    绝对值函数AddExitProc          ...

  6. android 获得电池状态

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  7. 自动化中间人攻击工具subterfuge小实验

    Subterfuge是一款用python写的中间人攻击框架,它集成了一个前端和收集了一些著名的可用于中间人攻击的安全工具. Subterfuge主要调用的是sslstrip,sslstrip 是08 ...

  8. Mqtt协议IOS端移植3

    ServerMqFramework.h #import "MqttFramework.h" @interface ServerMqFramework : MqttFramework ...

  9. HDU 2317 Nasty Hacks

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  10. java 短信猫发送短信的方法

    用java实现短信收发的功能,目前一般项目中短信群发功能的实现方法大致有下面三种: ·                 1. 向运行商申请短信网关,不需要额外的设备,利用运行商提供的API调用程序发送 ...