fhq_treap || BZOJ 3223: Tyvj 1729 文艺平衡树 || Luogu P3391 【模板】文艺平衡树(Splay)
题面: 【模板】文艺平衡树(Splay)
题解:无
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std;
inline int rd(){
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return f*x;
}
const int maxn=(1e5)+;
int N,M,tot=,val[maxn],siz[maxn],pr[maxn],rt=,chd[maxn][];
int L,R,x,y,z;
bool fl[maxn];
inline int New_node(int a){
val[++tot]=a;
siz[tot]=;
pr[tot]=rand();
return tot;
}
inline void Pushup(int a){
siz[a]=siz[chd[a][]]+siz[chd[a][]]+;
return;
}
inline void Pushdown(int a){
if(fl[a]){
swap(chd[a][],chd[a][]);
if(chd[a][])fl[chd[a][]]^=;
if(chd[a][])fl[chd[a][]]^=;
fl[a]=;
}
return;
}
inline int Merge(int a,int b){
if(!a||!b)return (a+b);
if(pr[a]<pr[b]){
Pushdown(a);
chd[a][]=Merge(chd[a][],b);
Pushup(a);
return a;
}
else{
Pushdown(b);
chd[b][]=Merge(a,chd[b][]);
Pushup(b);
return b;
}
}
inline void Split(int now,int k,int &x,int &y){
if(!now){x=y=; return;}
Pushdown(now);
if(siz[chd[now][]]+<=k){
x=now;
Split(chd[now][],k-siz[chd[now][]]-,chd[now][],y);
}
else {
y=now;
Split(chd[now][],k,x,chd[now][]);
}
Pushup(now);
return;
}
inline void Work(int now){
if(!now)return;
Pushdown(now);
Work(chd[now][]);
printf("%d ",val[now]);
Work(chd[now][]);
return;
}
int main(){
srand();
N=rd();M=rd();
for(int i=;i<=N;i++)rt=Merge(rt,New_node(i));
while(M--){
L=rd();R=rd();
Split(rt,L-,x,y);
Split(y,R-L+,y,z);
fl[y]^=;
rt=Merge(Merge(x,y),z);
}
Work(rt);
return ;
}
By:AlenaNuna
fhq_treap || BZOJ 3223: Tyvj 1729 文艺平衡树 || Luogu P3391 【模板】文艺平衡树(Splay)的更多相关文章
- BZOJ 3223: Tyvj 1729 文艺平衡树
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3628 Solved: 2052[Submit][Sta ...
- BZOJ 3223: Tyvj 1729 文艺平衡树(splay)
速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...
- bzoj 3223: Tyvj 1729 文艺平衡树 (splay)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3223 题面: 3223: Tyvj 1729 文艺平衡树 Time Limit: 10 S ...
- BZOJ 3223: Tyvj 1729 文艺平衡树-Splay树(区间翻转)模板题
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6881 Solved: 4213[Submit][Sta ...
- [BZOJ 3223 & Tyvj 1729]文艺平衡树 & [CodeVS 3243]区间翻转
题目不说了,就是区间翻转 传送门:BZOJ 3223 和 CodeVS 3243 第一道题中是1~n的区间翻转,而第二道题对于每个1~n还有一个附加值 实际上两道题的思路是一样的,第二题把值对应到位置 ...
- bzoj 3223/tyvj 1729 文艺平衡树 splay tree
原题链接:http://www.tyvj.cn/p/1729 这道题以前用c语言写的splay tree水过了.. 现在接触了c++重写一遍... 只涉及区间翻转,由于没有删除操作故不带垃圾回收,具体 ...
- BZOJ 3223 Tyvj 1729 文艺平衡树(Splay)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3223 [题目大意] 给出一数列,问m次区间翻转后的结果. [题解] Splay 区间翻 ...
- BZOJ - 3223 Tyvj 1729 文艺平衡树 (splay/无旋treap)
题目链接 splay: #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3f3f3f ...
- BZOJ 3223 Tyvj 1729 文艺平衡树 | Splay 维护序列关系
题解: 每次reverse(l,r) 把l-1转到根,r+1变成他的右儿子,给r+1的左儿子打个标记就是一次反转操作了 每次find和dfs输出的时候下放标记,把左儿子和右儿子换一下 记得建树的时候建 ...
随机推荐
- &&的运算顺序
先判断“&&”左侧的表达式,左侧的表达式为真时,再运算右侧的表达式.如左侧为假,则不运算右侧.
- Dubbo负载均衡:最少活跃数(LeastActive)
官方文档定义 最少活跃调用数,相同活跃数的随机,活跃数指调用前后计数差. 使慢的提供者收到更少请求,因为越慢的提供者的调用前后计数差会越大. 关于活跃数 最少活跃数负载均衡,最关键的点在于活跃数.活跃 ...
- Base64工具类并发问题!
为减少对象创建次数,一般会做如下编码: public class EncodeUtils { private static BASE64Encoder encoder; private static ...
- WPF SAP水晶报表例子和打包Setup
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=" ...
- xshell6,xftp下载
https://www.netsarang.com/zh/free-for-home-school/
- (转)使用NMAP工具扫描端口
原文:http://www.linuxde.net/2013/02/12354.html nmap 是一个用于网络探索或安全评测的工具.它支持 ping 扫描(判定哪些主机在运行),多端口扫描技术(判 ...
- 阶段3 1.Mybatis_11.Mybatis的缓存_4 mybatis一对多实现延迟加载
改成单表查询 首先配置的是select.他需要配置的值是accountDao中的方法,查询所有的账户,但是必须有条件.根据用户的id column配置的是id.因为要用user表的id去关联查询 Ac ...
- Python学习之==>第三方模块的安装、模块导入
一.模块&包 1.模块 模块实质上就是一个Python文件,它是用来组织代码的.意思就是把Python代码写在里面,文件名就是模块的名称.例如:random.py,random就是模块的名称. ...
- powered by Fernflower decompiler
About Fernflower Fernflower is the first actually working analytical decompiler for Java and probabl ...
- hadoop 2.5.2源码编译
编译过程漫长无比,错误百出,需要耐心耐心!! 1.准备的环境及软件 操作系统:Centos6.4 64位 jdk:jdk-7u80-linux-x64.rpm,不要使用1.8 maven:apache ...