#include <bits/stdc++.h>
#define ls son[x][0]
#define rs son[x][1]
#define int long long
using namespace std;
const int N=100010,mod=1e9+7,INF=0x3f3f3f3f3f3f3f3f;
int n,m;
int f[N],s[N],son[N][2],st[N],w[N],r[N];
static char buf[1000000],*paa=buf,*pd=buf;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline int read(void){
int u(0),t(1);char fc(getchar());
while(!isdigit(fc)){if(fc=='-') t=-1;fc=getchar();}
while(isdigit(fc)) u=(u<<1)+(u<<3)+(fc^48),fc=getchar();
return u*t;
}
inline void print(int u)
{
if(u<0) putchar('-'),u=-u;
if(u>9) print(u/10);
putchar(u%10+'0');
}
bool ntrt(int x){return son[f[x]][1]==x||son[f[x]][0]==x;}
void pushup(int x){s[x]=s[ls]^s[rs]^w[x];}
void pushson(int x){swap(ls,rs),r[x]^=1;}
void pushdown(int x)
{
if(r[x])
{
if(ls) pushson(ls);
if(rs) pushson(rs);
r[x]=0;
}
}
void rotate(int x)
{
int y=f[x],z=f[y],k=(son[y][1]==x),w=son[x][!k];
if(ntrt(y)) son[z][son[z][1]==y]=x;son[x][!k]=y;son[y][k]=w;
if(w) f[w]=y;f[y]=x;f[x]=z;
pushup(y);
}
void Splay(int x)
{
int y=x,tot=0;st[++tot]=y;
while(ntrt(y)) st[++tot]=y=f[y];
while(tot) pushdown(st[tot--]);
while(ntrt(x))
{
y=f[x];int z=f[y];
if(ntrt(y)) rotate((son[y][0]==x)^(son[z][0]==y)?x:y);
rotate(x);
}
pushup(x);
}
void access(int x){for(int y=0;x;x=f[y=x]) Splay(x),rs=y,pushup(x);}
void makert(int x){access(x);Splay(x);pushson(x);}
int findrt(int x)
{
access(x);Splay(x);
while(ls) pushdown(x),x=ls;
Splay(x);return x;
}
void split(int x,int y){makert(x);access(y);Splay(y);}
void link(int x,int y){makert(x);if(findrt(y)!=x)f[x]=y;}
void cut(int x,int y)
{
makert(x);
if(findrt(y)==x&&f[y]==x&&!son[y][0]) f[y]=son[x][1]=0,pushup(x);
}
signed main()
{
n=read(),m=read();
for(int i=1;i<=n;i++) w[i]=read();
for(int i=1,op,x,y;i<=m;i++)
{
op=read(),x=read(),y=read();
if(op==0) split(x,y),print(s[y]),puts("");
if(op==1) link(x,y);
if(op==2) cut(x,y);
if(op==3) Splay(x),w[x]=y;
}
return 0;
}剪贴板
剪贴板 twvxdays
剪贴板信息
剪贴板信息
- 收录
- 更新