code:
#include <set>
#include <map>
#include <cstdio>
#include <algorithm>
#define N 200007
#define lson s[x].ch[0]
#define rson s[x].ch[1]
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
struct LCT
{
int ch[2],rev,f,size;
}s[N];
int sta[N];
int get(int x) { return s[s[x].f].ch[1]==x; }
int Isr(int x) { return s[s[x].f].ch[0]!=x&&s[s[x].f].ch[1]!=x; }
void pushup(int x) { s[s[x].f].size=s[lson].size+s[rson].size+1; }
void rotate(int x)
{
int old=s[x].f,fold=s[old].f,which=get(x);
if(!Isr(old)) s[fold].ch[s[fold].ch[1]==old]=x;
s[old].ch[which]=s[x].ch[which^1];
if(s[old].ch[which]) s[s[old].ch[which]].f=old;
s[x].ch[which^1]=old,s[old].f=x,s[x].f=fold;
pushup(old),pushup(x);
}
void mark(int x)
{
s[x].rev^=1;
swap(lson,rson);
}
void pushdown(int x)
{
if(s[x].rev)
{
if(lson) mark(lson);
if(rson) mark(rson);
s[x].rev=0;
}
}
void Splay(int x)
{
int v=0,u=x,fa;
for(sta[++v]=u;!Isr(u);u=s[u].f) sta[++v]=s[u].f;
for(;v;--v) pushdown(sta[v]);
for(u=s[u].f;(fa=s[x].f)!=u;rotate(x)) if(s[fa].f!=u) rotate(get(fa)==get(x)?fa:x);
}
void Access(int x)
{
for(int y=0;x;y=x,x=s[x].f) Splay(x),rson=y,pushup(x);
}
void Move_to_Root(int x)
{
Access(x),Splay(x),mark(x);
}
struct node
{
int l,r;
node(int l=0,int r=0):l(l),r(r){}
};
map<int,node>t;
int main()
{
// setIO("input");
int i,j;
return 0;
}
原文:https://www.cnblogs.com/guangheli/p/12142720.html