#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int n, k, a[MAXN], len, ans[MAXN], cur, sum[MAXN];
int m;
int pin[MAXN];
struct c {
int l, r, idx;
}q[MAXN];
bool cmp(c a,c b){
if (a.l / len != b.l / len) {
return a.l < b.l;
}
return a.r < b.r;
}
void add(int i) {
pin[0]=1;
pin[sum[i]]++;
cur+=pin[sum[i]^k];
}
void del(int i) {
pin[0]=1;
pin[sum[i]]--;
cur-=pin[sum[i]^k];
}
int main() {
cin>>n>>m>>k;
for (int i = 1; i <= n; i++) {
cin>>a[i];
sum[i]=sum[i-1]^a[i];
}
len = sqrt(n);
for (int i = 1; i <= m; i++) {
int l, r;
cin>>l>>r;
q[i].l--;
q[i].idx=i;
}
sort(q,q+m,cmp);
int L = 1, R = 0;
for (int i=1;i<=m;i++) {
int l = q[i].l, r = q[i].r;
while (R < r) {
add(++R);
}
while (R > r) {
del(R--);
}
while (L < l) {
del(L++);
}
while (L > l) {
add(--L);
}
ans[q[i].idx] = cur;
}
for(int i = 1; i <= m; ++i){
cout << ans[i] << "\n";
}
return 0;
}
标签:cur,pin,int,sum,len,哪里,MAXN
From: https://blog.csdn.net/C202609liuyujia/article/details/140304983