题目链接:

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
  1. 3 1
    1 2 3
output
  1. 5
input
  1. 3 2
    1 2 3
output
  1. 3
input
  1. 3 3
    1 2 3
output
  1. 2
  2.  
  3. 题意
  4.  
  5. n个数,问有多少对数满足a[i]^a[i+1]^...^a[j]>=k;
  6.  
  7. 思路
  8.  
  9. 处理出前缀异或和,再用trie树搞;
  10.  
  11. AC代码
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define Riep(n) for(int i=1;i<=n;i++)
  4. #define Riop(n) for(int i=0;i<n;i++)
  5. #define Rjep(n) for(int j=1;j<=n;j++)
  6. #define Rjop(n) for(int j=0;j<n;j++)
  7. #define mst(ss,b) memset(ss,b,sizeof(b));
  8. typedef long long LL;
  9. const LL mod=1e9+;
  10. const double PI=acos(-1.0);
  11. const int inf=0x3f3f3f3f;
  12. const int N=2e7+;
  13. int n,k,cnt=;
  14. int tree[N][],val[N];
  15. void add_num(int num)
  16. {
  17. int x=;
  18. for(int i=;i>=;i--)
  19. {
  20. int y=(num>>i)&;
  21. if(!tree[x][y])tree[x][y]=cnt++;
  22. val[x]++;
  23. x=tree[x][y];
  24. }
  25. val[x]++;
  26. }
  27. LL get_ans(int num,int fy)
  28. {
  29. LL sum=;
  30. int x=;
  31. for(int i=;i>=;i--)
  32. {
  33. int y=(fy>>i)&;
  34. int fx=(num>>i)&^;
  35. if(y==)
  36. {
  37. sum+=(LL)val[tree[x][fx]];
  38. x=tree[x][fx^];
  39. }
  40. else x=tree[x][fx];
  41. }
  42. return sum+(LL)val[x];
  43. }
  44. int main()
  45. {
  46. scanf("%d%d",&n,&k);
  47. int pre=;
  48. LL ans=;
  49. add_num();
  50. Riep(n)
  51. {
  52. int a;
  53. scanf("%d",&a);
  54. pre^=a;
  55. ans+=(LL)get_ans(pre,k);
  56. add_num(pre);
  57. }
  58. printf("%I64d\n",ans);
  59.  
  60. return ;
  61. }
  1.  

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. AC日记——L国的战斗之间谍 洛谷 P1916

    题目背景 L国即将与I国发动战争!! 题目描述 俗话说的好:“知己知彼,百战不殆”.L国的指挥官想派出间谍前往I国,于是,选人工作就落到了你身上. 你现在有N个人选,每个人都有这样一些数据:A(能得到 ...

  2. Linux命令之ss

    1.ss -s 显示socket的统计信息 2.ss -a显示socket的详细信息 (ta:tcp,ua:udp) 3.ss -l显示本机监听的端口 4.ss -pl 显示本机监听的端口和程序 ht ...

  3. 某考试 T1 function

    (数据范围 n<=10^9 ,T<=10 ) 首先,我来证明一下 Σμ(d) * σ(i/d)^2 = σ(i^2) 相信做过约数个数和的童鞋都可以完成从右式推到左式,那么我现在就说一下怎 ...

  4. 利用BURPSUITE检测CSRF漏洞

    CSRF漏洞的手动判定:修改referer头或直接删除referer头,看在提交表单时,网站是否还是正常响应. 下面演示用Burpsuite对CSRF进行鉴定. 抓包. 成功修改密码完成漏洞的利用.

  5. SpringCloud中Rabbitmq的使用

    1.pom配置,添加以来jar包 <dependency> <groupId>org.springframework.cloud</groupId> <art ...

  6. 心情日记app总结 数据存储+服务+广播+listview+布局+fragment+intent+imagebutton+tabactivity+美工

    ---恢复内容开始--- 结果截图如下: 第一张图是程序主界面,主要是显示记事列表的一些个事件.旁边的侧拉框是自己登陆用的.可以设置密码.可以查看反馈与关于等信息. 点击第一张图片下方的图标,会显示不 ...

  7. LeetCode_3Sum

    一.题目 3Sum Total Accepted: 45112 Total Submissions: 267165My Submissions Given an array S of n intege ...

  8. 20160222.CCPP体系具体解释(0032天)

    程序片段(01):宽字符.c+字符串与内存四区.c 内容概要:宽窄字符 ///宽字符.c #include <stdio.h> #include <stdlib.h> #inc ...

  9. deepin os 15.4 切换jdk版本

    sudo update-alternatives --config javasudo update-alternatives --config javacsudo update-alternative ...

  10. openwrt gstreamer实例学习笔记(六. gstreamer Pads及其功能)

    一:概述 如我们在Elements一章中看到的那样,Pads是element对外的接口.数据流从一个element的source pad到另一个element的sink pad.pads的功能(cap ...