bzoj2157 LCT裸题
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF=1e9;
const int Maxn=40005;
int son[Maxn][2],sum[Maxn],minx[Maxn],maxx[Maxn];
int inv[Maxn],rev[Maxn],w[Maxn],fa[Maxn];
int n,m,x,y,i,a,u,v;
#define isroot(x) ( !((son[fa[x]][0]==x)||(son[fa[x]][1]==x)) )
void push1(int x){
swap(son[x][0],son[x][1]);
if (son[x][0]) rev[son[x][0]] ^= 1;
if (son[x][1]) rev[son[x][1]] ^= 1;
rev[x] = 0;
}
void push2(int x){
int L = son[x][0], R = son[x][1];
if (L){
sum[L] = -sum[L];
swap(minx[L],maxx[L]);
minx[L] = -minx[L];
maxx[L] = -maxx[L];
inv[L] ^= 1;
if (L>n) w[L]=-w[L];
}
if (R){
sum[R] = -sum[R];
swap(minx[R],maxx[R]);
minx[R] = -minx[R];
maxx[R] = -maxx[R];
inv[R] ^= 1;
if (R>n) w[R]=-w[R];
}
inv[x] = 0;
}
vo