这篇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 ;
}

文艺平衡树(区间翻转)(Splay模板)的更多相关文章

  1. Splay(区间翻转) 模板

    洛谷:P3391 [模板]文艺平衡树(Splay) #include<cstdio> #include<iostream> #include<algorithm> ...

  2. fhq_treap || BZOJ 3223: Tyvj 1729 文艺平衡树 || Luogu P3391 【模板】文艺平衡树(Splay)

    题面: [模板]文艺平衡树(Splay) 题解:无 代码: #include<cstdio> #include<cstring> #include<iostream> ...

  3. bzoj3223 文艺平衡树 codevs3303 翻转区间

    splay模版题吧 只有区间翻转 至于为什么要把须翻转区间旋到根 因为查找一个区间可以先找出他左端点左边第一个点和右端点x右边第一个点y 然后将x旋到根节点 y旋到x的右儿子 这样x的右边的点就是所有 ...

  4. bzoj3223 文艺平衡树 (treap or splay分裂+合并)

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 3313  Solved: 1883 [Submit][S ...

  5. 文艺平衡树 lg3391(splay维护区间入门)

    splay是支持区间操作的,先做这道题入个门 大多数操作都和普通splay一样,就不多解释了,只解释一下不大一样的操作 #include<bits/stdc++.h> using name ...

  6. BZOJ 3223 文艺平衡树 [codevs3303翻转区间]

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3223 通道2:http://codevs.cn/problem/3303/ 题目分析: 我 ...

  7. 【BZOJ3223】 Tyvj 1729 文艺平衡树 Splay

    Description   您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2  ...

  8. JZYZOJ1998 [bzoj3223] 文艺平衡树 splay 平衡树

    http://172.20.6.3/Problem_Show.asp?id=1998 平衡树区间翻转的板子,重新写一遍,给自己码一个板子. #include<iostream> #incl ...

  9. BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6881  Solved: 4213[Submit][Sta ...

  10. bzoj3223 Tyvj 1729 文艺平衡树(Splay Tree+区间翻转)

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2202  Solved: 1226[Submit][Sta ...

随机推荐

  1. ZOJ 3675 Trim the Nails(bfs)

    Trim the Nails Time Limit: 2 Seconds      Memory Limit: 65536 KB Robert is clipping his fingernails. ...

  2. ZOJ 3827 Information Entropy(数学题 牡丹江现场赛)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5381 Information Theory is one of t ...

  3. Oracle 闪回区满解决的方法

    闪回区满: OS: rm -rf [archivelog  autobackup  backupset  controlfile  flashback  onlinelog] eg : archive ...

  4. LeetCode 648. Replace Words (单词替换)

    题目标签:HashMap 题目给了我们一个array 的 root, 让我们把sentence 里面得每一个word 去掉它得 successor. 把每一个root 存入hash set,然后遍历s ...

  5. BeautifulSoup中各种html解析器的比較及使用

    Beautiful Soup解析器比較 ·Beautiful Soup支持各种html解析器.包含python自带的标准库.还有其它的很多第三方库模块. 当中一个就是lxml parser,至于lxm ...

  6. JSP页面的跳转及传值

    1.response.sendRedirect("跳转到页面的URL"); 该方法通过修改HTTP协议的HEADER部分,对浏览器下达重定向指令的,使浏览器显示重定向网页的内容. ...

  7. [python基础] python生成wordcloud并保存

    1.核心包 #jieba.pandas用来处理数据,数据源以xls格式存储的,这里用pandas进行处理import jieba from jieba import analyse import pa ...

  8. poj3469 Dual Core CPU——最小割

    题目:http://poj.org/problem?id=3469 最小割水题(竟然没能1A): 代码如下: #include<iostream> #include<cstdio&g ...

  9. 03、HelleBaiduMap

    D:\百度地图\百度地图\资料\百度地图与定位SDK\百度地图v3.5.0\BaiduMap_AndroidSDK_v3.5.0_All\BaiduMap_AndroidSDK_v3.5.0_Docs ...

  10. [Apple开发者帐户帮助]七、注册设备(3)禁用或启用设备

    您可以禁用和启用设备,但不能从开发者帐户中删除它.您可以禁用不再用于开发或测试的设备.但是,这样做会使包含设备的配置文件无效,并且不会增加当年设备的总数. 所需角色:帐户持有人或管理员. 在“ 证书” ...