#include <iostream>
#define ls(x) (s[x].ch[0])
#define rs(x) (s[x].ch[1])
#define fa(x) (s[x].fa)
#define son(x,f) (rs(f)==x)
#define conn(x,f,k) s[fa(x)=f].ch[k]=x
#define upd(x) s[x].sum=s[ls(x)].sum^s[rs(x)].sum^s[x].val
#define nrt(x) (ls(fa(x))==x or rs(fa(x))==x)
#define rota(x) swap(ls(x),rs(x)),s[x].rev^=1
using namespace std;
const int N=3E5+5;
struct node {
int ch[2];
int fa;
int val,siz;
bool rev;
int sum;
}s[N];
int st[N];
inline int pu(int p) {
if(s[p].rev) {
rota(ls(p));
rota(rs(p));
}
s[p].rev=false;
}
inline void pushall(int p) {
int top=0;
while(nrt(p)) {
st[++top]=p;
p=fa(p);
}
pu(p);
while(top)
pu(st[top--]);
}
inline void rot(int p) {
int f=fa(p),ff=fa(f),k=son(p,f);
conn(s[p].ch[k^1],f,k);
fa(p)=ff;
if(nrt(f))
s[ff].ch[son(f,ff)]=p;
conn(f,p,k^1);
upd(f);
upd(p);
}
inline void splay(int p) {
pushall(p);
while(nrt(p)) {
int f=fa(p),ff=fa(f);
if(nrt(f))
son(f,ff)^son(p,f)?rot(p):rot(f);
rot(p);
}
}
inline void access(int p) {
for(int y=0;p;p=fa(y=p)) {
splay(p);
rs(p)=y;
upd(p);
}
}
inline void mkrot(int p) {
access(p);
splay(p);
rota(p);
}
inline int findrot(int p) {
access(p);
splay(p);
while(ls(p)) {
pu(p);
p=ls(p);
}
splay(p);
return p;
}
inline void lnk(int x,int y) {
mkrot(x);
if(findrot(y)==x)
return ;
fa(x)=y;
}
inline void cut(int x,int y) {
mkrot(x);
if(fa(y)!=x or findrot(y)!=x or ls(y))
return ;
rs(x)=fa(y)=0;
upd(x);
}
inline void split(int x,int y) {
mkrot(x);
access(y);
splay(y);
}
int main() {
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>s[i].val;
while(m--) {
int opt,x,y;
cin>>opt>>x>>y;
if(opt==0) {
split(x,y);
cout<<s[y].sum<<endl;
}
if(opt==1)
lnk(x,y);
if(opt==2)
cut(x,y);
if(opt==3) {
splay(x);
s[x].val=y;
upd(x);
}
}
return 0;
}
第一个点下载下来看了,是通过的,但是到了洛谷就全RE了