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.

题意:

给定数列a[],和m个询问 Q(L,R),回答每个询问中有多少对(L<=i<=j<=R) ,使得异或为k。

异或转化为前缀和处理。然后就差不多交给分块处理了。

离线处理里比较好理解的一种,高中就会了,注意这里不多BB了。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int maxn=;
int a[maxn],pre[maxn],num[<<],n,m,k,sqrtn;
struct Query{
int id,l,r; ll ans;
}q[maxn];
bool cmp(const Query a,const Query b)
{
if(a.l/sqrtn==b.l/sqrtn) return a.r<b.r;
return a.l<b.l;
}
bool cmp2(const Query a,const Query b)
{
return a.id<b.id;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
sqrtn=(int)sqrt(n);
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
pre[i]=pre[i-]^a[i];
}
for(int i=;i<m;i++){
scanf("%d%d",&q[i].l,&q[i].r);
q[i].id=i;
}
sort(q,q+m,cmp);
int l=,r=;
num[pre[]]++;num[]++;
ll cur=(a[]==k?:);
for(int i=;i<m;i++)
{
while(r<q[i].r){
cur+=num[pre[r+]^k];
r++;
num[pre[r]]++;
}
while(l<q[i].l){
num[pre[l-]]--;
cur-=num[pre[l-]^k];
l++;
}
while(l>q[i].l){
cur+=num[pre[l-]^k];
num[pre[l-]]++;
l--;
}
while(r>q[i].r){
num[pre[r]]--;
cur-=num[pre[r]^k];
r--;
}
q[i].ans=cur;
}
sort(q,q+m,cmp2);
for(int i=;i<m;i++) printf("%lld\n",q[i].ans);
return ;
}

最新文章

  1. php json_encode数据格式化
  2. [ucgui] 对话框3——GUIBuilder生成界面c文件及修改
  3. 关于C++单件模式释放对象
  4. Conway&#39;s Game of Life: An Exercise in WPF, MVVM and C#
  5. 二模11day2解题报告
  6. Linux网络编程6&mdash;&mdash;使用TCP实现文件服务器
  7. 摩尔斯电码(Morse Code)Csharp实现
  8. git stash 保存修改现场
  9. start_kernel——local_irq_disable
  10. express源码分析---merge-descriptors
  11. “一切都是消息”--MSF(消息服务框架)入门简介
  12. Centos下的apache2练习
  13. python--类属性-实类属性--静态方法总结
  14. 01_ if 练习
  15. (钉钉)第三方WEB网站扫码登录
  16. svn目标计算机主动拒绝
  17. php远程获取图片或文件信息(get_headers,fsocketopen,curl)
  18. 禅道 bug指向为数字问题解决过程
  19. Ubuntu16.04下 protobuf3.4.0 的安装与卸载
  20. 基本控件文档-UITextField属性---iOS-Apple苹果官方文档翻译

热门文章

  1. vim diff 的使用
  2. C​P​U​_​C​S​t​a​t​e​_​P​S​t​a​t​e and then ACPI on Wiki
  3. php程序执行过程--非宏观和微观而是写的程序一行一行的路径----利用xdebug了解一段程序的执行过程----覆盖率
  4. ie6中利用jquery居中
  5. 小tip: DOM appendHTML实现及insertAdjacentHTML
  6. 多媒体开发之---h264 图像参数级语义
  7. ASP.NET RemoteAttribute远程验证更新问题
  8. smarty静态缓存
  9. EasyDSS高性能流媒体服务器前端重构(五)- webpack + vue-router 开发单页面前端实现按需加载 - 副本
  10. eclipse 安装tomcat