双倍经验求助
查看原帖
双倍经验求助
616733
Lysea楼主2023/12/3 17:37

和4462一模一样,但WA on 5

#include<bits/stdc++.h>
#define int long long
#define N 2000005
using namespace std;
struct node{
	int l,r,bel,idx,ans;
}e[N];
int n,m,k,a[N],s[N],t,cnt;
bool cmp(node x,node y){
	if(x.bel==y.bel) return x.r<y.r;
	return x.l<y.l;
}
bool cmp_(node x,node y){
	return x.idx<y.idx;
}
void add(int x){
	cnt+=s[a[x]^k];
	s[a[x]]++;
}
void del(int x){
	cnt-=s[a[x]^k];
	s[a[x]]--;
}
signed main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>k,t=sqrt(n);
	for(int i=1;i<=n;i++) cin>>a[i],a[i]^=a[i-1];
	for(int i=1;i<=m;i++){
		cin>>e[i].l>>e[i].r;
		e[i].l--,e[i].bel=(e[i].l-1)/t+1,e[i].idx=i;
	}
	sort(e+1,e+m+1,cmp);
	int l=1,r=0;
	for(int i=1;i<=m;i++){
		while(l<e[i].l) del(l++);
		while(l>e[i].l) add(--l);
		while(r>e[i].r) del(r--);
		while(r<e[i].r) add(++r);
		e[i].ans=cnt;
	}
	sort(e+1,e+m+1,cmp_);
	for(int i=1;i<=m;i++) cout<<e[i].ans<<endl;
    return 0;
}

2023/12/3 17:37
加载中...