这篇blog写的吼啊

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e5+;
int fa[N],cnt[N],son[N][],size[N],key[N],v[N],type,root;
int n,m,a[N];
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'')
{if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<='')
{x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
bool judge(int x)
{
return son[fa[x]][]==x;
}
void up(int x)
{
size[x]=size[son[x][]]+size[son[x][]]+;
}
void down(int x)
{
if(x&&v[x])
{
v[son[x][]]^=;
v[son[x][]]^=;
swap(son[x][],son[x][]);
v[x]=;
}
}
void rotate(int x)
{
int old=fa[x],oldf=fa[old],lr=judge(x);
down(old);down(x);
son[old][lr]=son[x][lr^];fa[son[old][lr]]=old;
son[x][lr^]=old;fa[old]=x;
fa[x]=oldf;
if(oldf)son[oldf][son[oldf][]==old]=x;
up(old);up(x);
}
void splay(int x,int goal)
{
for(int f;(f=fa[x])!=goal;rotate(x))
if(fa[f]!=goal)
rotate(judge(x)==judge(f)?f:x);
if(!goal)root=x;
}
int build(int f,int l,int r)
{
if(l>r)return ;
int mid=l+r>>,now=++type;
key[now]=a[mid];fa[now]=f;
v[now]=;
son[now][]=build(now,l,mid-);
son[now][]=build(now,mid+,r);
up(now);
return now;
}
int getrank(int x)
{
int now=root;
while()
{
down(now);
if(x<=size[son[now][]])now=son[now][];
else
{
x-=size[son[now][]]+;
if(!x)return now;
now=son[now][];
}
}
}
void rev(int l,int r)
{
l=getrank(l);
r=getrank(r+);
splay(l,);
splay(r,l);
down(root);
v[son[son[root][]][]]^=;
}
void print(int now)
{
down(now);
if(son[now][])print(son[now][]);
if(key[now]!=-0x3f3f3f3f&&key[now]!=0x3f3f3f3f)printf("%d ",key[now]);
if(key[son[now][]])print(son[now][]);
}
int main()
{
n=read();m=read();
for(int i=;i<=n;i++)a[i+]=i;
a[]=-0x3f3f3f3f;a[n+]=0x3f3f3f3f;
root=build(,,n+);
for(int i=;i<=m;i++)
{
int x=read(),y=read();
rev(x,y);
}
print(root);
return ;
}

最新文章

  1. apache中怎么配置网站的默认首页
  2. 自定cordova插件笔记demo
  3. Linux-TCP Queue的一些问题
  4. java如何区分是form表单请求,还是ajax请求
  5. 再识C中的结构体
  6. android 数据库的增删改查
  7. HTML5-36d嗨起^_^
  8. 杂记之activity之间的跳转
  9. C++可变参数的另一种实现
  10. .net异步性能测试(包括ASP.NET MVC WebAPI异步方法)
  11. SmokePing 部署实践
  12. Linux 下安装nodejs
  13. python的循环和选择
  14. react双向事件的绑定
  15. PriorityQueue 源码分析
  16. 携程Apollo配置中心架构深度剖析
  17. MySQL中间件方案盘点_搜狐科技_搜狐网
  18. 1126 Eulerian Path (25 分)
  19. 目标检测之rcnn---开启检测新高度优于dpm
  20. python学习之RabbitMQ-----消息队列

热门文章

  1. linux内核研究-8-块设备I/O层
  2. ZOJ 3868 GCD Expectation (容斥+莫比乌斯反演)
  3. centos6.2安装kvm虚拟机
  4. 1. MissingInteger 最小遗失整数 Find the minimal positive integer not occurring in a given sequence.
  5. $.getJSON() 未能执行回调函数的缘由
  6. Android开发之利用SQLite进行数据存储
  7. 运行Java -jar somefile.jar时发生了什么(二)
  8. 一分钟让你了解Microsoft Edge
  9. 桌面系统集成WEB认证系统方案
  10. bzoj1106