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, ..., aj is equal to k.
Input
The first line of the input contains integers n, m 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的整数数列a1,a2,…,an,给定查询参数l、r,问在al,al+1,…,ar区间内,有多少子序列满足异或和等于k。也就是说,对于所有的x,y(l≤x≤y≤r),满足ax⊕ax+1⊕⋯⊕ay=k的x,y有多少组。
输入
输入第一行为3个整数n,m,k。第二行为空格分开的n个整数,即a1,a2,…,an。接下来m行,每行两个整数lj,rj,代表一次查询。
输出
输出共m行,对应每个查询的计算结果。
如果区间 [i,j] 的异或值为k,则 sum[j]^sum[i-1]=k ; sum[i-1]^k=sum[j]; sum[j]^k=sum[i-1]
当区间移动时 如果右端点加了一个值t ,sum[t]=x我们是知道的 所以整个区间的答案增加了 cnt[x^k]个
因为 x^x^k=k;
需要注意到 因为判断的时候始终要用到左端点的前一个值 所以我们输入时直接让l--;
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<algorithm>
#include<iomanip>
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
const int mod = 1e9 + 7;
const double esp = 1e-5;
const double PI = 3.14159265358979;
using namespace std;
const int N = 1e6 + 5;
const int maxn = 1 << 20;
/*int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
ll _power(int a, int b)//快速幂
{
int ans=1, res=a;
while(b){
if(b&1) ans=ans*res%mod;
res=res*res%mod;
b>>=1;
}
return ans%mod;*/
struct node {
int l, r, id;
}Q[maxn];
int pos[maxn];
ll flag[maxn];//记录每个前缀出现的次数
ll ans[maxn];
int a[maxn];
bool cmp(node a, node b) {
if (pos[a.l] == pos[b.l])
return a.r < b.r;
return pos[a.l] < pos[b.l];//否则按照块来排序
}
int n, m, k;
int L = 1, R = 0;
ll Ans = 0;
void add(int x) {
Ans += flag[a[x] ^ k];
flag[a[x]]++;
}
void del(int x) {
flag[a[x]]--;
Ans -= flag[a[x] ^ k];
}
int main() {
scanf("%d%d%d", &n, &m, &k);
int sz = sqrt(n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] = a[i] ^ a[i - 1];
pos[i] = i / sz;
}
for (int i = 1; i <= m; i++) {
scanf("%d%d", &Q[i].l, &Q[i].r);
Q[i].id = i;
}
sort(Q + 1, Q + 1 + m, cmp);
flag[0] = 1;
for (int i = 1; i <= m; i++) {
while (L < Q[i].l) {
del(L - 1);
L++;
}
while (L > Q[i].l) {
L--;
add(L - 1);
}
while (R < Q[i].r) {
R++;
add(R);
}
while (R > Q[i].r) {
del(R);
R--;
}
ans[Q[i].id] = Ans;
}
for (int i = 1; i <= m; i++)
cout << ans[i] << endl;
}