Problem surface
Description
A n integer sequence a[1],a[2] , a[n], given the query parameters l,r, how many continuous subsets are there in the [l,r] interval
The sequence satisfies the exclusive or and equals k.
That is to say, for a l l x, y (l ≤ x ≤ y ≤ r), a[x]^a[x+1] ^ ^How many groups of X, y of a[y]=k.
Input
The first line of the input file is three integers n, m, k.
The second line is n integers separated by spaces, i.e. ai, a2 .an.
Next m lines, two integers lj and rj for each line, represent a query.
1≤n,m≤105,O≤k,ai≤105,1≤lj≤rj≤n
Output
The output file consists of m lines, corresponding to the calculation results of each query.
Sample Input
4 5 1
1 2 3 1
1 4
1 3
2 3
2 4
4 4
Sample Output
4
2
1
2
1
Title Solution
Board question + original question
I have nothing to say.
It's really a template contest...
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define RG register
#define MAX 111111
inline int read()
{
RG int x=0,t=1;RG char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return x*t;
}
ll ans[MAX],Ans;
int n,m,K,blk,num[MAX],a[MAX];
struct Query{int l,r,id,lb;}q[MAX];
bool operator<(Query a,Query b){if(a.lb!=b.lb)return a.lb<b.lb;return a.r<b.r;}
void Add(int x){Ans+=num[K^a[x]],++num[a[x]];}
void Del(int x){--num[a[x]],Ans-=num[K^a[x]];}
int main()
{
n=read();m=read();K=read();blk=sqrt(n);
for(int i=1;i<=n;++i)a[i]=read()^a[i-1];
for(int i=1;i<=m;++i)
{
int l=read(),r=read();
q[i]=(Query){l-1,r,i,l/blk};
}
sort(&q[1],&q[m+1]);
int L=0,R=-1;
for(int i=1;i<=m;++i)
{
while(R<q[i].r)Add(++R);
while(L>q[i].l)Add(--L);
while(L<q[i].l)Del(L++);
while(R>q[i].r)Del(R--);
ans[q[i].id]=Ans;
}
for(int i=1;i<=m;++i)printf("%lld\n",ans[i]);
return 0;
}