lct模板吧..要维护好哦
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 330000
int sum[N],ch[N][2],a[N],fa[N],rev[N],n,m;
void update(int p){sum[p]=sum[ch[p][0]]^a[p]^sum[ch[p][1]];}
bool isroot(int x){return x!=ch[fa[x]][0] && x!=ch[fa[x]][1];}
void pushdown(int x){
if(!rev[x]) return;
rev[ch[x][0]]^=1;rev[ch[x][1]]^=1;rev[x]^=1;
swap(ch[x][0],ch[x][1]);
}
void push(int x){
if(!isroot(x)) push(fa[x]);
pushdown(x);
}
void rotate(int x){
int y=fa[x],z=fa[y],t=ch[y][0]==x;
if(!isroot(y)) ch[z][ch[z][1]==y]=x;
fa[y]=x;fa[x]=z;fa[ch[x][t]]=y;
ch[y][t^1]=ch[x][t];ch[x][t]=y;
update(y);update(x);
}
void splay(int x){
push(x);
while(!isroot(x)){
int y=fa[x];
if(isroot(y)){rotate(x);return;}
if(ch[y][0]==x^ch[fa[y]][0]==y) rotate(x);
else rotate(y);rotate(x);
}
}
void access(int x){
int y=0;
while(x){
splay(x);ch[x][1]=y;update(x);
y=x;x=fa[x];
}
}
void makeroot(int x){
access(x);splay(x);rev[x]^=1;
}
int find(int x){
access(x);splay(x);
while(ch[x][0]) x=ch[x][0];
return x;
}
void link(int x,int y){
if(find(x)==find(y)) return;
makeroot(x);fa[x]=y;
}
void cut(int x,int y){
makeroot(x);access(y);splay(y);
if(ch[y][0]==x) ch[y][0]=fa[x]=0;update(y);
}
void query(int x,int y){
makeroot(x);access(y);splay(y);
printf("%d\n",sum[y]);
}
void change(int x,int y){
splay(x);a[x]=y;update(x);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=m;i++){
int op,x,y;scanf("%d%d%d",&op,&x,&y);
if(op==0) query(x,y);
else if(op==1) link(x,y);
else if(op==2) cut(x,y);
else change(x,y);
}
return 0;
}