Splay(区间翻转) 模板
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=;
int n,m,tp,root,CNT;
int key[MAXN],lz[MAXN],fa[MAXN],sz[MAXN],val[MAXN],q[MAXN],Q[MAXN],ch[MAXN][];
void update(int k){ sz[k]=sz[ch[k][]]+sz[ch[k][]]+; }
void rotate(int x,int &y)
{
int old=fa[x],oldf=fa[old],op=ch[old][]==x;
if(old==y) y=x;
else ch[oldf][ch[oldf][]==old]=x;
fa[x]=oldf;
fa[ch[x][op^]]=old; ch[old][op]=ch[x][op^];
fa[old]=x; ch[x][op^]=old;
update(old); update(x);
}
void down(int x)
{
if(lz[x])
{
lz[x]^=; lz[ch[x][]]^=; lz[ch[x][]]^=;
swap(ch[x][],ch[x][]);
}
}
void splay(int x,int &y)
{
int now=x,old,oldf;Q[++tp]=now;
while(now!=y) Q[++tp]=fa[now] , now=fa[now];
while(tp--) down(Q[tp]);
while(x!=y)
{
old=fa[x],oldf=fa[old];
if(old!=y){
if((ch[old][]==x)^(ch[oldf][]==old)) rotate(x,y);
else rotate(old,y);
}
rotate(x,y);
}
}
void Build(int &k,int ll,int rr,int FA)
{
int mid=(ll+rr)/;
k=++CNT; fa[k]=FA; key[k]=val[mid];
if(mid>ll) Build(ch[k][],ll,mid-,k);
if(mid<rr) Build(ch[k][],mid+,rr,k);
update(k);
}
int findx(int x)//注意下放。
{
int now=root;
while()
{
down(now);
if(x<=sz[ch[now][]]) now=ch[now][];
else
{
x-=sz[ch[now][]]+;
if(x==) return now;
else now=ch[now][];
}
}
}
void rev(int L,int R)
{
int ll=findx(L-),rr=findx(R+);
splay(ll,root);
splay(rr,ch[root][]);
lz[ch[ch[root][]][]]^=;
}
void dfs(int u)
{
down(u);
if(ch[u][]) dfs(ch[u][]);
if(key[u]!=&&key[u]!=n+) printf("%d ",key[u]);
if(ch[u][]) dfs(ch[u][]);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)val[i]=i;
Build(root,,n+,);
for(int i=,L,R;i<=m;i++)
{
scanf("%d%d",&L,&R);
L++; R++; rev(L,R);
}
dfs(root); puts("");
return ;
}
Splay(区间翻转) 模板的更多相关文章
- BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6881 Solved: 4213[Submit][Sta ...
- splay区间翻转
原题P3391 [模板]文艺平衡树(Splay) 题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作: ...
- hdu-1890-Robotic Sort splay区间翻转
题意: 依次找第i大的数下标pos[i],然后将区间[i,pos[i]]翻转 分析: splay树区间翻转 // File Name: ACM/HDU/1890.cpp // Author: Zlbi ...
- bzoj 3223 文艺平衡树 splay 区间翻转
Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 17715 Solved: 7769[Submit][Status][ ...
- bzoj 1251序列终结者 splay 区间翻转,最值,区间更新
序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 4594 Solved: 1939[Submit][Status][Discuss] De ...
- BZOJ 3223 Splay区间翻转
思路: 区间翻转的裸题 终于tm理解splay了-- //By SiriusRen #include <cstdio> #include <cstring> #include ...
- Splay(区间翻转)&树套树(Splay+线段树,90分)
study from: https://tiger0132.blog.luogu.org/slay-notes P3369 [模板]普通平衡树 #include <cstdio> #inc ...
- [bzoj3223]文艺平衡树(splay区间反转模板)
解题关键:splay模板题. #include<cstdio> #include<cstring> #include<algorithm> #include< ...
- hdu1890 Robotic Sort (splay+区间翻转单点更新)
Problem Description Somewhere deep in the Czech Technical University buildings, there are laboratori ...
- 2019牛客国庆集训派对day1 K题 双向链表练习题 splay区间翻转
题目链接: 解法: 先建n颗平衡树,合并的时候将a中最右的结点翻转到根节点,b中最左的结点翻转到根节点,对合并后的根节点进行标记. #include <bits/stdc++.h> usi ...
随机推荐
- The JSP specification requires that an attribute name is preceded by whitespace--异常
异常信息:org.apache.jasper.JasperException: /pages/selectedCourse.jsp (line: 4, column: 39) The JSP spec ...
- Kotlin基本语法笔记之函数、变量的定义及null检测
定义函数 fun sum(a: Int, b: Int): Int { return a + b } 该函数中两个参数的类型都是Int,返回类型是Int 也可以做如下简化 fun sum(a: Int ...
- POJ 2823 Sliding Window (滑动窗口的最值问题 )
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 41264 Accepted: 12229 ...
- APP测试走过的那些坑
我现在的工作有一大部分也是app测试,虽然自己是app开发出身,但是在测试上还是跌入了很多大坑,毕竟二者还是有很大不同,所处的角度也是不一样的.而开发转测试中,我认为较难的也是一个角度的转换,以一个开 ...
- easyui tree 树形节点 formatter 渲染不起作用
接了个需求,需要对一个树形列表进行重新渲染,在进行渲染的过程中发现树形节点的formatter 属性无法生效.经反复测试,发现在外部环境中正常,但在项目环境中始终无效.最终发现问题出在 easyui ...
- 关于Spring Security的笔记
1.web.xml配置文件 加载Spring Security,将DelegatingFilterProxy配置在DispatcherServlet之前. <filter> <fil ...
- 【C/C++】获取当前系统时间
#include<iostream> #include<Ctime> using namespace std; int main() { time_t t; time(& ...
- Android-Styles and Themes [From API Guide]
This blog was opened 5 months ago and it has 57 posts now,but the poor thing is by now no one has co ...
- 记SCOI2017
Day1完挂,OI再见. 居然卡进去了. UESTC的评测机见鬼啊,我本地不到1s.时限是3s的两道题都T了,然后就少了50pt. Day1 T1看完首先O(n^2)DP是裸的,然后感觉n选k好像不能 ...
- MTCNN人脸检测识别笔记
论文:Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks 论文链接:https:// ...