Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., ajis equal to k.

Input

The first line of the input contains integers nm and k (1 ≤ n, m ≤ 100 000, 0 ≤ k ≤ 1 000 000) — the length of the array, the number of queries and Bob's favorite number respectively.

The second line contains n integers ai (0 ≤ ai ≤ 1 000 000) — Bob's array.

Then m lines follow. The i-th line contains integers li and ri (1 ≤ li ≤ ri ≤ n) — the parameters of the i-th query.

Output

Print m lines, answer the queries in the order they appear in the input.

Example

Input
6 2 3
1 2 1 1 0 3
1 6
3 5
Output
7
0
Input
5 3 1
1 1 1 1 1
1 5
2 4
1 3
Output
9
4
4

Note

In the first sample the suitable pairs of i and j for the first query are: (1, 2), (1, 4), (1, 5), (2, 3), (3, 6), (5, 6), (6, 6). Not a single of these pairs is suitable for the second query.

In the second sample xor equals 1 for all subarrays of an odd length.

题意:这道题意思为:给你一行数,让你查找在这行数中有多少子区间满足其内的数亦或为K;

题解:可以让sum[i]表示从1亦或到i的值;sum[i]^=sum[i-1];

sum[r]=k^sum[l-1];(l,r分别表示左右端点)

AC代码为:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4;
struct node
{
friend bool operator< (node x, node y)
{
if (x.pos == y.pos)return x.r<y.r;
return x.l<y.l;
}
int l, r, id;
int pos;
};
node qu[N];
int n, m, k;
int b[N], num[2 * N];
long long ans[N];
void solve()
{
memset(num, 0, sizeof(num));
int le = 1, ri = 0;
long long temp = 0;
for (int i = 1; i <= m; i++)
{
while (ri<qu[i].r)
{
ri++;
temp += num[b[ri] ^ k];
num[b[ri]]++;
}
while (ri>qu[i].r)
{
num[b[ri]]--;
temp -= num[b[ri] ^ k];
ri--;
}
while (le>qu[i].l - 1)
{
le--;
temp += num[b[le] ^ k];
num[b[le]]++;
}
while (le<qu[i].l - 1)
{
num[b[le]]--;
temp -= num[b[le] ^ k];
le++;
}
ans[qu[i].id] = temp;
}
}
int main()
{
b[0] = 0;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++)
{
scanf("%d", &b[i]);
b[i] ^= b[i - 1];
}
int s = sqrt(n);
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &qu[i].l, &qu[i].r);
qu[i].id = i;
qu[i].pos = qu[i].l / s;
}
sort(qu + 1, qu + m + 1);
solve();
for (int i = 1; i <= m; i++)
{
cout << ans[i] << "\n";
}
return 0;
}

CoderForces-617B的更多相关文章

  1. coderforces #387 Servers(模拟)

    Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  2. coderforces #384 D Chloe and pleasant prizes(DP)

    Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. coderforces 731c

    题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...

  4. coderforces 721b

    题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. CoderForces 280B(记忆化搜索)

    题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...

  6. codeforces 617B Chocolate

    题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...

  7. Codeforces 617B:Chocolate(思维)

    题目链接http://codeforces.com/problemset/problem/617/B 题意 有一个数组,数组中的元素均为0或1 .要求将这个数组分成一些区间,每个区间中的1的个数均为1 ...

  8. CoderForces 689A Mike and Cellphone (水题)

    题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...

  9. CoderForces 518C Anya and Smartphone (模拟)

    题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少 ...

  10. CoderForces 518D Ilya and Escalator (期望DP)

    题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...

随机推荐

  1. Hybrid App: 看看第三方WebViewJavascriptBridge是如何来实现Native和JavaScript交互

    一.简介 在前面两篇文章中已经介绍了Native与JavaScript交互的几种方式,依次是JavaScriptCore框架.UI组件UIWebView.WebKit框架,这几种方式都是苹果公司提供的 ...

  2. redhat、centos7系列破解密码

    redhat或者centos7,破解密码: 1.开机出现引导菜单时按下e键 2.找到linux16行,在其后追加 rd.break 参数 console=tty0 3.启动到特定的模式,由于更改密码需 ...

  3. [java笔记] 最近学的一些笔记

    1.@Override的用法 2.父类的返回值类型的范围,与子类返回值类型的返回的大小关系: 3.子类方法的权限修饰符,与子类方法的权限修饰符: 4.如果p1是一个对象,p2也是个对象,那么代码p1= ...

  4. go中的数据结构通道-channel

    1. channel的使用 很多文章介绍channel的时候都和并发揉在一起,这里我想把它当做一种数据结构来单独介绍它的实现原理. channel,通道.golang中用于数据传递的一种数据结构.是g ...

  5. 021.掌握Pod-Pod调度策略

    一 Pod生命周期管理 1.1 Pod生命周期 Pod在整个生命周期过程中被系统定义了如下各种状态. 状态值 描述 Pending API Server已经创建该Pod,且Pod内还有一个或多个容器的 ...

  6. thinkphp6.0 开启调试模式以及Driver [Think] not supported

    thinkphp6.0 开启调试模式 首先确认自己是通过 composer 进行的下载,然后修改系统目录下的 .example.env 为 .env 文件 修改 config->app.php ...

  7. pat 1124 Raffle for Weibo Followers(20 分)

    1124 Raffle for Weibo Followers(20 分) John got a full mark on PAT. He was so happy that he decided t ...

  8. 【前端知识体系-CSS相关】CSS工程化方案

    1.如何解决CSS的模块化问题? 使用Less,Sass等CSS预处理器 使用PostCSS插件(postcss-import/precss) 使用webpack处理CSS(css-loader + ...

  9. JS如何在不给新空间的情况下给数组去重?

    1.先排序,在让相邻元素对比去重 const nums = [3, 1, 1, 5, 2, 3, 4, 3, 5, 5, 6, 4, 6, 6, 6]; Array.prototype.arrayNo ...

  10. 遗忘root密码,应该如何修改?[CentOS7.5]

    https://www.lanzous.com/i71hw6d 下载视频演示 实验环境:VMware Workstation [CentOS7.5]遗忘root用户密码 应该如何修改??? 设置BIO ...