CodeForces 665E Beautiful Subarrays

题意:问你有多少个区间,异或起来大于等于k

思路:显然求个前缀和之后,就等于有多少对数异或起来大于等于k了,每次暴力爬字典树就好了,当k这一位等于0的时候,我们可以直接加上另外一边1的子树大小,因为爬那边之后,我怎么爬都是大于等于k的


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e7+6;
struct Tri
{
    int ch[maxn][2];
    int sz[maxn];
    int tot;
    void init()
    {
        memset(ch,0,sizeof(ch));
        memset(sz,0,sizeof(sz));
        tot=2;
    }
    void insert(int x)
    {
        int u=1;
        for(int i=30;i>=0;i--)
        {
            int p = (x>>i)&1;
            if(!ch[u][p])ch[u][p]=tot++;
            sz[u]++;
            u=ch[u][p];
        }
        sz[u]++;
    }
    int get(int x,int y)
    {
        int u=1;
        long long ans = 0;
        for(int i=30;i>=0;i--)
        {
            int p = (x>>i)&1^1;
            int q = (y>>i)&1;
            if(q==0)ans+=sz[ch[u][p]],u=ch[u][p^1];
            else u=ch[u][p];
        }
        return ans+sz[u];
    }
}T;
int main()
{
    T.init();
    int n,k;
    scanf("%d%d",&n,&k);
    int pre = 0;
    long long ans = 0;
    T.insert(0);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        pre^=x;
        ans+=T.get(pre,k);
        T.insert(pre);
    }
    cout<<ans<<endl;
}

Description

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.

Sample Input

Input
3 1
1 2 3
Output
5
Input
3 2
1 2 3
Output
3
Input
3 3
1 2 3
Output
2



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值