快改的和题解一样了,但是就是 WA/ll
#include<bits/stdc++.h>
using namespace std;
struct Splay{
stack<int> stk;
int rt, tot, fa[300005], ch[300005][2], sum[300005], vl[300005], cnt[300005], sz[300005];
bool r[300005];
void pup(int u){
sum[u] = sum[ch[u][0]] ^ sum[ch[u][1]] ^ vl[u];
}
bool isr(int u){
return u == ch[fa[u]][1];
}
bool unr(int u){
return (ch[fa[u]][0] == u || ch[fa[u]][1] == u);
}
void rev(int u){
swap(ch[u][0], ch[u][1]);
r[u] ^= 1;
}
void pdn(int u){
if (r[u]){
if (ch[u][0])
rev(ch[u][0]);
if (ch[u][1])
rev(ch[u][1]);
r[u] = 0;
}
}
void rtt(int u){
int v = fa[u], w = fa[v], op = isr(u);
if (unr(v))
ch[w][isr(v)] = u;
ch[u][op ^ 1] = v;
ch[v][op] = ch[u][op ^ 1];
if (ch[u][op ^ 1])
fa[ch[u][op ^ 1]] = v;
fa[v] = u;
fa[u] = w;
pup(v);
// pup(u);
}
void splay(int u){
int v = u, w;
stk.push(v);
while (unr(v)){
v = fa[v];
stk.push(v);
}
while (!stk.empty()){
pdn(stk.top());
stk.pop();
}
while (unr(u)){
v = fa[u];
if (unr(v)){
if (isr(u) ^ isr(v))
rtt(u);
else
rtt(v);
}
rtt(u);
}
pup(u);
}
void access(int u){
for (int v = 0; u; v = u, u = fa[u]){
splay(u);
ch[u][1] = v;
pup(u);
}
}
void mkrt(int u){
access(u);
splay(u);
rev(u);
}
int qrt(int u){
access(u);
splay(u);
while (ch[u][0]){
pdn(u);
u = ch[u][0];
}
splay(u);
return u;
}
void split(int u, int v){
mkrt(u);
access(v);
splay(v);
}
void link(int u, int v){
mkrt(u);
if (qrt(v) != u)
fa[u] = v;
}
void cut(int u, int v){
mkrt(u);
if (qrt(v) == u && fa[v] == u && !ch[v][0]){
ch[u][1] = 0;
fa[v] = 0;
pup(u);
}
}
}tr;
int n, q;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> tr.vl[i];
while (q--){
int op, u, v;
cin >> op >> u >> v;
if (op == 0){
tr.split(u, v);
cout << tr.sum[v] << "\n";
}else if (op == 1)
tr.link(u, v);
else if (op == 2)
tr.cut(u, v);
else if (op == 3){
tr.splay(u);
tr.vl[u] = v;
}
}
return 0;
}