#include<bits/stdc++.h>
using namespace std;
const int Maxn=int(1e5);
inline int read()
{
char ch=getchar();
int f=1,x=0;
while(ch>'9' || ch<'0')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
struct Node
{
int l,r,siz;
int val,key,tag;
} t[Maxn+5];
int tot,root,n,m;
#define ls(x) t[x].l
#define rs(x) t[x].r
inline int Newnode(int x)
{
t[++tot]=(Node){0,0,1,x,rand(),0};
return tot;
}
inline void Update(int x)
{
t[x].siz=t[ls(x)].siz+t[rs(x)].siz+1;
}
inline void push_down(int x)
{
if(!t[x].tag) return;
t[x].tag=0,swap(ls(x),rs(x));
t[ls(x)].tag^=1,t[rs(x)].tag^=1;
}
inline void Split(int now,int siz,int &x,int &y)
{
if(!now) {x=y=0; return;}
push_down(now);
if(t[ls(now)].siz+1<=siz)
x=now,Split(rs(now),siz-t[ls(now)].siz-1,rs(now),y);
else
y=now,Split(ls(now),siz,x,ls(now));
Update(now);
}
inline int Merge(int x,int y)
{
if(!x || !y) return x+y;
else if(t[x].key<=t[y].key)
{
push_down(x);
rs(x)=Merge(rs(x),y),Update(x);
return x;
}
else
{
push_down(y);
ls(y)=Merge(x,ls(y)),Update(y);
return y;
}
}
inline void Solve(int l,int r)
{
int a,b,c;
Split(root,r,a,c),Split(a,l-1,a,b);
t[b].tag^=1;
root=Merge(a,Merge(b,c));
}
inline void dfs(int x)
{
if(!x) return;
push_down(x),dfs(ls(x));
printf("%d ",t[x].val);
dfs(rs(x));
}
int main()
{
srand(time(0));
n=read(),m=read();
for(register int i=1;i<=n;++i)
root=Merge(root,Newnode(i));
while(m--)
{
int l=read(),r=read();
Solve(l,r);
}
dfs(root);
return 0;
}剪贴板
剪贴板 6aojh6oz
剪贴板信息
剪贴板信息
- 发布
- 收录
- 更新