闲的没事打了打一个splay,,,,,
注意只要是遍历数据结构就要下传标记!!!!
只要是修改就要维护所有受到影响的!!!
希望以后不要再犯这种zz错误了hhh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define ll long long
#define maxn 100005
using namespace std;
int ch[maxn][2],f[maxn],root;
int n,m,siz[maxn],tag[maxn];
int le,ri,q[maxn],tp;
inline int get(int x){
return ch[f[x]][1]==x;
}
inline void update(int x){
siz[x]=1+siz[ch[x][1]]+siz[ch[x][0]];
}
inline void pushdown(int x){
if(tag[x]){
tag[x]=0,swap(ch[x][0],ch[x][1]);
tag[ch[x][0]]^=1,tag[ch[x][1]]^=1;
}
}
inline void rotate(int x){
int fa=f[x],ffa=f[fa],tp=get(x);
ch[fa][tp]=ch[x][tp^1],f[ch[fa][tp]]=fa;
ch[x][tp^1]=fa,f[fa]=x;
f[x]=ffa;
if(ffa) ch[ffa][ch[ffa][1]==fa]=x;
if(fa==root) root=x;
update(fa),update(x);
}
inline void splay(int x,int d){
for(int i=x;i;i=f[i]) q[++tp]=i;
for(;tp;tp--) pushdown(q[tp]);
for(;f[x]!=d;rotate(x))
if(f[f[x]]!=d) rotate(get(f[x])==get(x)?f[x]:x);
}
inline int kth(int x){
int now=root;
while(1){
pushdown(now);
if(x<=siz[ch[now][0]]){
now=ch[now][0];
}
else{
x-=1+siz[ch[now][0]];
if(!x) return now;
now=ch[now][1];
}
}
}
int build(int l,int r,int fa){
if(l>r) return 0;
int mid=l+r>>1;
f[mid]=fa,siz[mid]=r-l+1;
ch[mid][0]=build(l,mid-1,mid);
ch[mid][1]=build(mid+1,r,mid);
return mid;
}
void print(int x){
pushdown(x);
if(ch[x][0]) print(ch[x][0]);
if(x>1&&x<=n) printf("%d\n",x-1);
if(ch[x][1]) print(ch[x][1]);
}
int main(){
scanf("%d%d",&n,&m);
root=build(1,n+2,0);
while(m--){
scanf("%d%d",&le,&ri);
int aa=kth(le),bb=kth(ri+2);
int sz=ri-le+1,rot;
splay(aa,0),splay(bb,aa);
rot=ch[ch[root][1]][0];
f[rot]=ch[ch[root][1]][0]=0;
update(ch[root][1]),update(root);
tag[rot]^=1;
aa=kth(n-sz+1),splay(aa,0);
ch[ch[root][1]][0]=rot,f[rot]=ch[root][1];
update(ch[root][1]),update(root);
}
n++;
print(root);
return 0;
}