样例没过为何AC
输入
5 14
114
514
19
19
810
1 1 2
0 1 2
2 1 2
1 1 2
1 2 3
2 1 3
1 1 3
1 4 5
1 2 5
0 3 5
0 3 4
3 5 233333
0 1 5
0 2 5
正确输出
624
315
296
232709
232823
我的输出
624
329
346
232709
232823
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m;
int a[N];
int son[N][2],f[N],mark[N],sum[N];
bool isRoot(int x)
{
return x!=son[f[x]][0]&&x!=son[f[x]][1];
}
bool get_son(int x)
{
return x==son[f[x]][1];
}
void pushup(int x)
{
sum[x]=sum[son[x][0]]^sum[son[x][1]]^a[x];
}
void rotate(int x)
{
int y=f[x],z=f[y],chx=get_son(x),chy=get_son(y);
f[x]=z;
if(!isRoot(y))son[z][chy]=x;
son[y][chx]=son[x][chx^1];
f[son[x][chx^1]]=y;
son[x][chx^1]=y;
f[y]=x;
pushup(y);
pushup(x);
pushup(z);
}
void pushdown(int x)
{
if(mark[x])
{
if(son[x][0])swap(son[son[x][0]][0],son[son[x][0]][1]),mark[son[x][0]]^=1;
if(son[x][1])swap(son[son[x][1]][0],son[son[x][1]][1]),mark[son[x][1]]^=1;
mark[x]=0;
}
}
void update(int x)
{
if(!isRoot(x))update(f[x]);
pushdown(x);
}
void splay(int x)
{
update(x);
for(int p;p=f[x],!isRoot(x);rotate(x))
if(!isRoot(p)) rotate(get_son(x)==get_son(p)?p:x);
}
void Access(int x)
{
for(int p=0;x;p=x,x=f[x])
splay(x),son[x][1]=p,pushup(x);
}
int find(int x)
{
Access(x);
splay(x);
pushdown(x);
while(son[x][0])x=son[x][0],pushdown(x);
splay(x);
return x;
}
void makeroot(int x)
{
Access(x);
splay(x);
swap(son[x][0],son[x][1]);
mark[x]^=1;
}
int ask(int x,int y)
{
makeroot(x);
Access(y);
splay(x);
// update(y);
// while(f[y])cout<<y<<" ",y=f[y];
// cout<<y<<" ";
return sum[x];
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i],sum[i]=a[i];
for(int i=1;i<=m;i++)
{
int op,x,y;
cin>>op>>x>>y;
if(op==0)
{
cout<<ask(x,y)<<endl;
}
else if(op==1)
{
if(find(x)!=find(y))
makeroot(x),f[x]=y;
}
else if(op==2)
{
if(find(x)==find(y))
{
makeroot(x),Access(y),splay(y);
if(f[x]==y&&son[y][0]==x)f[x]=son[y][0]=0,pushup(y);
}
}
else
{
splay(x);
sum[x]=sum[x]^y^a[x];
a[x]=y;
}
}
return 0;
}