求助
查看原帖
求助
800499
suzhikz楼主2024/12/12 14:38
#include<bits/stdc++.h>
#define ll long long
#define reg register
#define db double
#define il inline
using namespace std;
void read(int &x){x=0;int f=1;char c=getchar();while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;}
void read(ll &x){x=0;int f=1;char c=getchar();while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;}
const int N=3e5+5; 
int n,m,ch[N*24][2],tot,cnt[N*24];
int rt[N];
void ins(int x1,int x2,int pos,int w){
	if(pos<0)return;
	int tmp=(w>>pos)&1;
//	cout<<x1<<' '<<x2<<' '<<pos<<' '<<w<<' '<<tmp<<endl;
	ch[x1][!tmp]=ch[x2][!tmp];
	ch[x1][tmp]=++tot;
	cnt[ch[x1][tmp]]=cnt[ch[x2][tmp]]+1;
	ins(ch[x1][tmp],ch[x2][tmp],pos-1,w);
}
int query(int x1,int x2,int pos,int w){
	if(pos<0)return 0;
	int tmp=(w>>pos)&1;
	if(cnt[ch[x1][!tmp]]>cnt[ch[x2][!tmp]]){
		return (1<<pos)+query(ch[x1][!tmp],ch[x2][!tmp],pos-1,w);
	}else{
//		cout<<ch[x1][tmp]<<' '<<ch[x2][tmp]<<' '<<cnt[ch[x1][tmp]]<<' '<<cnt[ch[x2][tmp]]<<endl;
		return query(ch[x1][tmp],ch[x2][tmp],pos-1,w);
	}
}
int main(){
	read(n);read(m);
	ins(++tot,0,25,0);
	rt[0]=1;
	int la=0;
	for(int u,i=1;i<=n;i++){
		read(u);
		rt[i]=++tot;la^=u;
//		cout<<la<<endl;
		ins(rt[i],rt[i-1],25,la);
	}
	for(int i=1;i<=m;i++){
		char c;int l,r,x;
		cin>>c;
		if(c=='A'){
			read(x);la^=x;
			rt[++n]=++tot;ins(rt[n],rt[n-1],25,la);
		}else{
			read(l);read(r);read(x);l--;r--;
			printf("%d\n",query(rt[l],rt[r],25,la^x));
		}
	}
	
	return 0;
}

2024/12/12 14:38
加载中...