求助,为什么70(RE4-6)
查看原帖
求助,为什么70(RE4-6)
51128
ZGS_WZY楼主2020/5/27 13:54
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
int co[500010];int pre[500010];int w[500010];int in[500010];
int bel[500010];
struct wzy{ 
	int l,r,id;
}d[500010];
inline bool cmp(wzy a,wzy b){
	return (bel[a.l]!=bel[b.l])?(a.l<b.l):((bel[a.l]&1)==(a.r<b.r));
}
	
int cnt[500010];long long f[500010];long long ans=0;
inline void add(int x){
	if(in[pre[x]])ans+=1ll*cnt[in[pre[x]]];
	cnt[pre[x]]++;return;
}
inline void del(int x){
	cnt[pre[x]]--;
	if(in[pre[x]])ans-=1ll*cnt[in[pre[x]]];
	return;
}

int main(){
	int n,m,k;read(n);read(m);read(k);int l=sqrt(n);
	rep(i,1,n){bel[i]=i/l;read(co[i]);pre[i]=(pre[i-1]^co[i]);w[i]=pre[i];}
	w[n+1]=0;
	sort(w+1,w+n+2);int len=unique(w+1,w+n+2)-w-1;
	rep(i,0,n)pre[i]=lower_bound(w+1,w+len+1,pre[i])-w;
	
	rep(i,0,n){
		if(in[pre[i]])continue;
		int ll=1;int rr=len;int pos=0;
		while(ll<=rr){
			int mid=(ll+rr)>>1;
			if(w[mid]<(w[pre[i]]^k)){ll=mid+1;}
			else if(w[mid]>(w[pre[i]]^k)){rr=mid-1;}
			else{pos=mid;break;}
		}
		in[pre[i]]=pos;
	}
	
	rep(i,1,m){read(d[i].l);read(d[i].r);d[i].l--;d[i].id=i;}
	sort(d+1,d+m+1,cmp);
	int ll=0;int rr=0;cnt[pre[0]]++;
	rep(i,1,m){
		while(rr<d[i].r){rr++;add(rr);}
		while(ll>d[i].l){ll--;add(ll);}
		while(ll<d[i].l){del(ll);ll++;}
		while(rr>d[i].r){del(rr);rr--;}
		f[d[i].id]=ans;
	}
	rep(i,1,m)write(f[i]);
	return 0;
}
2020/5/27 13:54
加载中...