为啥这个代码会全部 MLE 啊 /kk
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cerr << #x << " = " << x << endl;
template < typename Tp >
inline void rd(Tp &x) {
x = 0; int fh = 1; char ch = 1;
while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if(ch == '-') fh = -1, ch = getchar();
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
x *= fh;
}
template < typename Tp >
inline void chrd(Tp &x) {
char ch = 1;
while(ch != 'Q' && ch != 'U') ch = getchar();
if(ch == 'U') x = 1;
else x = 2;
}
#define int long long
const int mod = 998244353;
template < typename Tp > inline void smax(Tp &x, Tp y) {if(x < y) x = y;}
template < typename Tp > inline void smin(Tp &x, Tp y) {if(x > y) x = y;}
template < typename Tp > inline void chkadd(Tp &x, Tp y) {x = (x + y) % mod;}
template < typename Tp > inline Tp abs(Tp x) {return (x < 0) ? -x : x;}
const int maxn = 1000000 + 7;
const int maxm = 2000000 + 7;
int n, Q;
int Head[maxn], to[maxm], Next[maxm], tot;
int v[maxn];
void add(int x, int y) {
to[++tot] = y, Next[tot] = Head[x], Head[x] = tot;
}
inline void Init(void) {
rd(n); rd(Q);
for(int i = 1; i <= n; i++) rd(v[i]);
for(int i = 1, x, y; i < n; i++) {
rd(x); rd(y);
add(x, y); add(y, x);
}
}
int size[maxn], son[maxn], top[maxn], dfn[maxn], Pre[maxn], ind;
int fa[maxn], dep[maxn];
void dfs1(int x, int f) {
dep[x] = dep[f] + 1, fa[x] = f, size[x] = 1;
int mx = -1;
for(int i = Head[x]; i; i = Next[i]) {
int y = to[i];
if(y == f) continue;
dfs1(y, x); size[x] += size[y];
if(size[y] > mx) mx = size[y], son[x] = y;
}
}
void dfs2(int x, int tp) {
top[x] = tp, dfn[x] = ++ind, Pre[ind] = x;
if(!son[x]) return ;
dfs2(son[x], tp);
for(int i = Head[x]; i; i = Next[i]) {
int y = to[i];
if(y == fa[x] || y == son[x]) return ;
dfs2(y, y);
}
}
#define lson (x << 1)
#define rson ((x << 1) | 1)
#define mid ((l + r) >> 1)
int val[maxn << 2], tag[maxn << 2];
void build(int x, int l, int r) {
// assert(l <= r);
if(l == r) {val[x] = v[Pre[l]]; return ;}
build(lson, l, mid); build(rson, mid + 1, r);
}
void modify(int x, int l, int r, int L, int R, int necc) {
// assert(l <= r); assert(L <= R);
if(L <= l && r <= R) {tag[x] ^= necc; return ;}
if(L <= mid) modify(lson, l, mid, L, R, necc);
if(R > mid) modify(rson, mid + 1, r, L, R, necc);
}
int query(int x, int l, int r, int pos) {
// assert(l < r);
if(l == r) return val[x] ^ tag[x];
int res;
if(pos <= mid) res = query(lson, l, mid, pos);
else res = query(rson, mid + 1, r, pos);
return res ^ tag[x];
}
#undef lson
#undef rson
#undef mid
int d[500];
inline bool insert(int x) {
for(int i = 30; i >= 0; i--) if((x >> i) & 1){
if(!d[i]) {d[i] = x; return true;}
x ^= d[i]; if(!x) return false;
}
return true;
}
inline void clear(void) {memset(d, 0, sizeof(d));}
inline int LCA(int x, int y) {
while(top[x] != top[y]) {
if(dep[top[x]] < dep[top[y]]) swap(x, y);
x = fa[top[x]];
}
if(dep[x] < dep[y]) return x;
return y;
}
inline void op1(void) {
int x, y, z; rd(x); rd(y); rd(z);
while(top[x] != top[y]) {
if(dep[top[x]] < dep[top[y]]) swap(x, y);
modify(1, 1, n, dfn[top[x]], dfn[x], z);
x = fa[x];
}
if(dep[x] > dep[y]) swap(x, y);
modify(1, 1, n, dfn[x], dfn[y], z);
}
inline void op2(void) {
int x, y; rd(x); rd(y);
int lca = LCA(x, y);
clear();
if(dep[x] + dep[y] - 2 * dep[lca] + 1 >= 31) {
puts("YES"); return ;
}
while(x != lca) {
if(!insert(query(1, 1, n, dfn[x]))) {
puts("YES"); return ;
}
x = fa[x];
}
while(y != lca) {
if(!insert(query(1, 1, n, dfn[y]))) {
puts("YES"); return ;
}
y = fa[y];
}
if(!insert(query(1, 1, n, dfn[lca]))) puts("YES");
else puts("NO");
// printf("%d\n", query(1, 1, n, 1));
// printf("%d\n", query(1, 1, n, 2));
}
inline void Work(void) {
dfs1(1, 0); dfs2(1, 1);
build(1, 1, n);
while(Q--) {
string sl; cin >> sl;
// int op; chrd(op);
if(sl[0] == 'U') op1();
else op2();
}
}
signed main(void) {
Init();
Work();
return 0;
}