E. Beautiful Subarrays
 

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
 
题意:
  
  给你n个数的序列,问你多少区间的异或值大于等于k
 
题解:
  
  对于每一个前缀我们插入trie中,
  询问当前前缀与之前前缀的异或值大于等于k就好
 
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 2e7+;
  4. struct Tri
  5. {
  6. int ch[maxn][];
  7. int sz[maxn];
  8. int tot;
  9. void init()
  10. {
  11. memset(ch,,sizeof(ch));
  12. memset(sz,,sizeof(sz));
  13. tot=;
  14. }
  15. void insert(int x)
  16. {
  17. int u=;sz[u]++;
  18. for(int i=;i>=;i--)
  19. {
  20. int p = (x>>i)&;
  21. if(!ch[u][p])ch[u][p]=tot++;
  22. u=ch[u][p]; sz[u]++;
  23. }
  24. }
  25. int get(int x,int y)
  26. {
  27. int u=;
  28. long long ans = ;
  29. for(int i=;i>=;i--)
  30. {
  31. int p = (x>>i)&^;
  32. int q = (y>>i)&;
  33. if(q==)ans+=sz[ch[u][p]],u=ch[u][p^];
  34. else u=ch[u][p];
  35. if(u==) return ans;
  36. }
  37. return ans+sz[u];
  38. }
  39. }T;
  40. int main()
  41. {
  42. T.init();
  43. int n,k;
  44. scanf("%d%d",&n,&k);
  45. int pre = ;
  46. long long ans = ;
  47. T.insert();
  48. for(int i=;i<=n;i++)
  49. {
  50. int x;scanf("%d",&x);
  51. pre^=x;
  52. ans+=T.get(pre,k);
  53. T.insert(pre);
  54. }
  55. cout<<ans<<endl;
  56. return ;
  57. }

Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数的更多相关文章

  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 预处理+二叉树优化

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

  3. Educational Codeforces Round 12 E Beautiful Subarrays

    先转换成异或前缀和,变成询问两个数异或≥k的方案数. 分治然后Trie树即可. #include<cstdio> #include<algorithm> #define N 1 ...

  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. 软件需求规范说明 (Software Requirements Specification, 简称SRS)

    GB/T 9385-2008 笔记 为了形成确定和完备的规格说明, 我们需要明确 软件的顾客希望得到什么; 软件的供方理解用户想要什么; 4.2 SRS的基本性质 SRS是对在具体环境中执行确定功能的 ...

  2. 浅析CLR的异常处理模型

    文章目录: 异常概述 CLR中的异常处理机制 CLR中异常的核心类System.Exception类 异常处理的设计规范和最佳实践 异常处理的性能问题 其他拓展 1.异常概述 异常我们通常指的是行动成 ...

  3. javascript中构造函数的三种方式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. form-control给input添加这个class类后就会使用bootstrap自带的input框

    <input type="text" class="form-control" id="name" placeholder=" ...

  5. required输入框为必填项

    required <input type="text" placeholder="cat photo URL" required>

  6. java 常用API 包装 数据转换

    package com.oracel.demo01; public class Sjzh { // 将基本数据类型转字符串 public static void main(String[] args) ...

  7. c++ 优先级队列(priority_queue)

    从网上搜优先级队列用法,都是有些乱七八糟的,有几种用法都没说,直接贴代码.实在郁闷,于是自己在此归纳归纳. 废话不多说,直入主题. 优先级队列的核心是比较函数的实现. 比较函数有两种实现方法: 1.在 ...

  8. Java常用类(I)-时间和日期

    java开发中,常涉及到时间的处理,这里就做一个总结,同样也是一个笔记. 相关类及概念 1. java.util.Date:表示特定的瞬间,精确到毫秒.由于API 不易于实现国际化,日期和时间字段之间 ...

  9. DAO DTO VO BO

    DAO叫数据访问对象DTO是数据传输对象DAO通常是将非对象数据(如关系数据库中的数据)以对象的方式操纵.DTO通常用于不同层(UI层.服务层或者域模型层)直接的数据传输,以隔离不同层,降低层间耦合 ...

  10. 【vue】v-if和v-show的区别

    今天来捋一下vue中的v-if与v-show的区别 先来看一下vue官方文档对他们的解释 2.从实现方式来看: v-if是当依赖的值变为false时,直接让元素消失,html代码也会消失,相当于直接在 ...