Register @ 2020-01-14 09:48:01
RT.我代码里rotate是先pushup的x再pushup的y都能A掉这题,我还是在敲LCT的时候才发现这里有锅的。。。
代码:
#include <cstdio>
int t,n,m,rt;
inline int read(){
char ch=getchar();int res=0,w=1;
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {res=res*10+ch-'0';ch=getchar();}
return res*w;
}
struct node{
int v,fa,sz,ad,c[2];
}a[100003];
inline void Swap(int&x,int&y) {int te=x;x=y;y=te;}
inline void pushup(int pos) {a[pos].sz=a[a[pos].c[0]].sz+a[a[pos].c[1]].sz+1;}
inline void pushdown(int pos){
if(a[pos].ad) {a[pos].ad=0;a[a[pos].c[0]].ad^=1;a[a[pos].c[1]].ad^=1;Swap(a[pos].c[0],a[pos].c[1]);}
}
inline void add(int f,int v) {a[++n].v=v;a[n].sz=1;a[n].sz=1;a[n].fa=f;a[f].c[v>a[f].v]=n;}
inline void connect(int f,int s,int x) {a[f].c[s]=x;a[x].fa=f;}
inline void rotate(int x) {int y=a[x].fa,z=a[y].fa;int u=(a[y].c[0]==x)?0:1,v=(a[z].c[0]==y)?0:1;connect(y,u,a[x].c[u^1]);connect(x,u^1,y);connect(z,v,x);pushup(x);pushup(y);}
inline void splay(int x,int to){
int p=a[to].fa;
while(a[x].fa!=p)
{
int y=a[x].fa,z=a[y].fa;
if(a[x].fa!=to) ((a[y].c[0]==x)^(a[z].c[0]==y))?rotate(x):rotate(y);
rotate(x);
}
if(!p) rt=x;
}
void ins(int now,int x,int f){
if(!n) {add(0,x);rt=n;return;}
if(!now) {add(f,x);splay(n,rt);return;}
a[now].sz++;ins(a[now].c[x>a[now].v],x,now);
}
inline int kth(int x){
int now=rt;
while(1)
{
pushdown(now);
if(a[a[now].c[0]].sz>=x) now=a[now].c[0];
else if(a[a[now].c[0]].sz+1==x) return now;
else {x-=a[a[now].c[0]].sz+1;now=a[now].c[1];}
}
}
inline void write(int now){
pushdown(now);
if(a[now].c[0]) write(a[now].c[0]);
if(a[now].v>1&&a[now].v<t+2) printf("%d ",a[now].v-1);
if(a[now].c[1]) write(a[now].c[1]);
}
int main(){
t=read();m=read();
for(register int i=1;i<=t+2;i++) ins(rt,i,0);
while(m--) {int l=read(),r=read();l=kth(l);r=kth(r+2);splay(l,rt);splay(r,a[l].c[1]);a[a[r].c[0]].ad^=1;}
write(rt);
return 0;
}
by zmx_wzx_JY @ 2020-01-14 15:08:33
tql
by zmx_wzx_JY @ 2020-01-14 15:08:47
LCTtql
by ieeqwq @ 2020-01-15 13:33:08
114514
by bluebluewind @ 2020-02-19 16:58:34
tpl
by Apeiria @ 2020-03-21 18:37:52
楼下讨论提到的U70453