0 pts 求调
查看原帖
0 pts 求调
1023793
yaodiguoan楼主2024/5/18 09:32

提交记录

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#define hh putchar('\n')
#define kg putchar(' ')
#define debug puts("debug")
#define int long long
//#define int __int128
namespace quickread{
	inline int read(){
		int x=0,f=1;char ch=getchar();
		while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
		while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
		return x*f;
	}
	inline void write(int x){
	    if(x<0){putchar('-');x=-x;}
	    if(x>9)write(x/10);
	    putchar(x%10+'0');
	}
}
using namespace quickread;
const int N=1e6+10,inf=2147483647;
int n,m,k,block,pos[N],a[N],ans[N],cnt[N];
struct node{
	int l,r,id;
} q[N];
bool cmp(node A,node B){
	if(pos[A.l]!=pos[B.l]) return pos[A.l]<pos[B.l];
	if(pos[A.l]&1) return A.r>B.r;
	return A.r<B.r;
}
int l=1,r,now;
void add(int x){
	now+=cnt[a[x]^k];
	cnt[a[x]]++;
}
void del(int x){
	cnt[a[x]]--;
	now-=cnt[a[x]^k];
}
signed main(){
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	n=read(),m=read(),k=read();block=sqrt(n);
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]^read();
		pos[i]=(i-1)/block+1;
	}
	cnt[0]=1;
	for(int i=1;i<=m;i++){
		q[i].l=read();q[i].r=read();
		q[i].id=i;
	}
	sort(q+1,q+m+1,cmp);
	for(int i=1;i<=m;i++){
		while(l<q[i].l) del(l++);
		while(l>q[i].l) add(--l);
		while(r<q[i].r) add(++r);
		while(r>q[i].r) del(r--);
		ans[q[i].id]=now;
	}
	for(int i=1;i<=m;i++) write(ans[i]),hh;
	
	return 0;
}
2024/5/18 09:32
加载中...