E. XOR and Favorite Number
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 thatl ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., aj is 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.

Examples
input

Copy
6 2 3
1 2 1 1 0 3
1 6
3 5
output

Copy
7
0
input

Copy
5 3 1
1 1 1 1 1
1 5
2 4
1 3
output

Copy
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.

题意:有n个数和m次询问,每一询问会有一个L和R,表示所询问的区间,

问在这个区间中有多少个连续的子区间的亦或和为k

假设我们现在有一个前缀异或和数组sum[],现在我们要求区间[L,R]的异或的值,

用sum数组表示就是sum[L-1]^sum[R]==K,或者说是K^sum[R]==sum[L-1]

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e6 + ;
int n, m, k, L, R, sz, a[maxn];
LL sum[maxn], ans, ANS[maxn];
struct node {
int l, r, id;
node() {}
node(int l, int r, int id): l(l), r(r), id(id) {}
bool operator <(const node & a)const {
if (l / sz == a.l / sz) return r < a.r;
return l < a.l;
}
} qu[maxn];
void add(int x) {
ans += sum[a[x] ^ k];
sum[a[x]]++;
}
void del(int x) {
sum[a[x]]--;
ans -= sum[a[x] ^ k];
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= n ; i++) {
scanf("%d", &a[i]);
a[i] ^= a[i - ];
}
for (int i = ; i <= m ; i++) {
scanf("%d%d", &qu[i].l, &qu[i].r);
qu[i].l--;
qu[i].id = i;
}
sz = (int)sqrt(n);
sort(qu + , qu + m + );
L = , R = ;
for (int i = ; i <= m ; i++) {
while(L > qu[i].l) add(--L);
while(R < qu[i].r) add(++R);
while(L < qu[i].l) del(L++);
while(R > qu[i].r) del(R--);
ANS[qu[i].id] = ans;
}
for (int i = ; i <= m ; i++)
printf("%lld\n", ANS[i]);
return ;
}

最新文章

  1. Tomcat部署的时候 unpackWARs=&quot;true&quot;
  2. Jdbc如何从PostgreSql读取海量数据?PostgreSql源代码分析纪录
  3. 10、面向对象以及winform的简单运用(isMdicontainer的设置、timer控件进行倒计时的制作)
  4. Java Collections的排序之二
  5. jquery css快捷方法
  6. ECSHOP 数据库结构说明 (适用版本v2.7.3)
  7. poj2484--A Funny♂Game
  8. PowerShell_零基础自学课程_9_高级主题:静态类和类的操作
  9. UIImage 图片处理:截图,缩放,设定大小,存储
  10. Qt入门之基础篇(1):Qt4及Qt5的下载与安装
  11. Tcl与Design Compiler (七)——环境、设计规则和面积约束
  12. Python 列表(List) 的三种遍历(序号和值)方法
  13. PMBook - 以考PMP为项目,整理项目章程
  14. vue.js学习资料
  15. 【UML】NO.55.EBook.8.UML.3.001-【UML和模式应用 第3版】
  16. java并发编程系列一、多线程
  17. javascript性能优化之避免重复工作
  18. Chapter 3 Phenomenon——15
  19. Java学习笔记之:Spring MVC 环境搭建
  20. 创建ros的程序包--3

热门文章

  1. Spring Cloud(十一):服务网关 Zuul(过滤器)【Finchley 版】
  2. 211. String Permutation【LintCode by java】
  3. python 打包
  4. Java进阶知识点:服务端高并发的基石 - NIO与Reactor AIO与Proactor
  5. java日期格式处理
  6. android入门 — PopupWindow
  7. Css入门课程 Css基础
  8. css那些事儿1 css选择符与管理
  9. c语言作业1
  10. 如何设置windows 2003的最大远程连接数