Splay又写挫了。。。。。。。。
回头复习一下维修数列和LCT吧,不然Splay真不会写了。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=80000+5;
const int inf=1e9;
int id[N],ch[N][2],fa[N],a[N],root,sz[N],node,key[N],n,m;
inline void pushup(int x){sz[x]=sz[ch[x][0]]+sz[ch[x][1]]+1;}
inline void rotate(int x,int &k){
int y=fa[x],z=fa[y],l=ch[y][1]==x,r=l^1;
if(y==k)k=x;
else ch[z][ch[z][1]==y]=x;
fa[x]=z;fa[y]=x;fa[ch[x][r]]=y;
ch[y][l]=ch[x][r];ch[x][r]=y;
pushup(y);pushup(x);
}
inline void splay(int x,int &k){
while(x!=k){
int y=fa[x],z=fa[y];
if(y!=k){
if(ch[y][0]==x^ch[z][0]==y)rotate(x,k);
else rotate(y,k);
}
rotate(x,k);
}
}
void build(int l,int r,int f){
if(l>r)return;
int