bzo j4825 [Hnoi2017]单旋
Description

Input
Output
#include<cstdio>
#include<set>
const int N=1e5+;
namespace lct{
#define lc ch][0
#define rc ch][1
#define fa ch][2
#define sz ch][3
int ch[N][];
bool nrt(int x){
return x==x[fa][lc]||x==x[fa][rc];
}
void up(int x){
x[sz]=+x[lc][sz]+x[rc][sz];
}
void rot(int x){
int f=x[fa],g=f[fa],d=x==f[rc];
if(nrt(f))g[ch][g[rc]==f]=x;
x[fa]=g;
(f[ch][d]=x[ch][d^])[fa]=f;
(x[ch][d^]=f)[fa]=x;
up(f);up(x);
}
void sp(int x){
while(nrt(x)){
int f=x[fa];
if(nrt(f))rot((x==f[lc])==(f==f[fa][lc])?f:x);
rot(x);
}
}
void acs(int x){
for(int y=;x;sp(x),x[rc]=y,up(x),y=x,x=x[fa]);
}
void ct(int x){
acs(x);sp(x);
x[lc][fa]=;
x[lc]=;
up(x);
}
void lk(int x,int y){
sp(x);
x[fa]=y;
}
void query(int x){
acs(x);
sp(x);
printf("%d\n",x[lc][sz]+);
}
#undef lc
#undef rc
#undef fa
#undef sz
}
#define G *++ptr
char buf[N*],*ptr=buf-;
int q,o,x,rt=,ch[N][],fa[N],p=;
int _(){
int x=,c=G;
while(c<)c=G;
while(c>)x=x*+c-,c=G;
return x;
}
struct pos{
int x,y;
bool operator<(pos w)const{return x<w.x;}
};
std::set<pos>st;
void setc(int w,int d,int u){
fa[ch[w][d]=u]=w;
lct::lk(u,w);
}
void setc(int w,int d){
int u=ch[w][d];
fa[u]=ch[w][d]=;
lct::ct(u);
}
void ins(int x){
int u=++p;
lct::ch[u][]=;
if(!rt){
rt=u;
}else{
std::set<pos>::iterator it=st.upper_bound((pos){x,});
if(it==st.end()||ch[it->y][]){
--it;
setc(it->y,,u);
}else{
setc(it->y,,u);
}
}
lct::query(u);
st.insert((pos){x,u});
}
int main(){
fread(buf,,sizeof(buf),stdin)[buf]=;
for(q=_();q;--q){
o=_();
if(o==){
x=_();
ins(x);
}else if(o==||o==){
int w=st.begin()->y,c=ch[w][],f=fa[w];
lct::query(w);
if(f){
setc(f,);
if(c)setc(w,),setc(f,,c);
if(o==)setc(w,,rt),rt=w;
}else if(o==){
if(c)setc(w,),rt=c;
}
if(o==)st.erase(st.begin());
}else if(o==||o==){
int w=(--st.end())->y,c=ch[w][],f=fa[w];
lct::query(w);
if(f){
setc(f,);
if(c)setc(w,),setc(f,,c);
if(o==)setc(w,,rt),rt=w;
}else if(o==){
if(c)setc(w,),rt=c;
}
if(o==)st.erase(--st.end());
}
if(st.empty())rt=;
}
return ;
}
bzo j4825 [Hnoi2017]单旋的更多相关文章
- bzoj 4825: [Hnoi2017]单旋 [lct]
4825: [Hnoi2017]单旋 题意:有趣的spaly hnoi2017刚出来我就去做,当时这题作死用了ett,调了5节课没做出来然后发现好像直接用lct就行了然后弃掉了... md用lct不知 ...
- 【LG3721】[HNOI2017]单旋
[LG3721][HNOI2017]单旋 题面 洛谷 题解 20pts 直接模拟\(spaly\)的过程即可. 100pts 可以发现单旋最大.最小值到根,手玩是有显然规律的,发现只需要几次\(lin ...
- 4825: [Hnoi2017]单旋
4825: [Hnoi2017]单旋 链接 分析: 以后采取更保险的方式写代码!!!81行本来以为不特判也可以,然后就总是比答案大1,甚至出现负数,调啊调啊调啊调~~~ 只会旋转最大值和最小值,以最小 ...
- [BZOJ4825][HNOI2017]单旋(线段树+Splay)
4825: [Hnoi2017]单旋 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 667 Solved: 342[Submit][Status][ ...
- 【BZOJ4825】[Hnoi2017]单旋 线段树+set
[BZOJ4825][Hnoi2017]单旋 Description H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据结构,因为代码好写,功能 ...
- bzoj4825 [Hnoi2017]单旋
Description H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据结构,因为代码好写,功能多,效率高,掌握这种数据结构成为了 H 国的必 ...
- BZOJ:4825: [Hnoi2017]单旋
Description H 国是一个热爱写代码的国家,那里的人们很小去学校学习写各种各样的数据结构.伸展树(splay)是一种数据结构,因为代码好写,功能多,效率高,掌握这种数据结构成为了 H 国的必 ...
- HNOI2017 单旋
题目描述 网址:https://www.luogu.org/problemnew/show/3721 大意: 有一颗单旋Splay(Spaly),以key值为优先度,总共有5个操作. [1] 插入一个 ...
- HNOI2017单旋
单旋 这道题做法贼多,LCT,splay,线段树什么的貌似都行. 像我这种渣渣只会线段树了(高级数据结构学了也不会用). 首先离线所有操作,因为不会有两个点值重复,所以直接离散. 一颗线段树来维护所有 ...
随机推荐
- 为pyhon安装opencv扩展包出现distributed 1.21.8 requires msgpack, which is not installed.【转】
本文转载自:https://blog.csdn.net/weixin_39513374/article/details/81051466 pip install msgpack-python pip ...
- Scan法求凸包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 给一个半径和n个点 求圆的周长 + n个点的凸包的周长 #include<bits/std ...
- springboot中websoket的使用
知识点:springboot项目中,websoket实时推送技术的介绍与使用 一.双向通信 http协议通信只能由客户端发起请求,服务端返回查询结果,如果我们想定时获取服务端的状态变化,相对 ...
- CSU 1968 Permutation Descent Counts
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1968 题意:对于任一种N的排列A,定义它的E值为序列中满足A[i]>A[i+1]的数的个 ...
- POJ 1730 Perfect Pth Powers(唯一分解定理)
http://poj.org/problem?id=1730 题意:给出一个n,a=b^p,求出最大p值. 思路: 首先利用唯一分解定理,把n写成若干个素数相乘的形势.接下来对于每个指数求最大公约数, ...
- 安全之路:Web渗透技术及实战案例解析(第2版)
安全之路:Web渗透技术及实战案例解析(第2版)
- ongene database
http://ongene.bioinfo-minzhao.org/index.html
- SDK manager 中 Done loading packages 问题
1.在选项栏中点击tools,选择Optons… 在弹出的设置窗口中勾选Force https://…sources to be fetched using http://… 然后点击Close 4. ...
- codeforces 355 div2 C. Vanya and Label 水题
C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- SpringBoot在启动时的多环境配置以及加载顺序
通常我们在开发完成一个SpringBoot项目时,总是要打包部署的. 在启动SpringBoot应用时,我们常常会使用命令java -jar xxx.jar来启动这个服务. 命令java -jar 除 ...