博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu3436 splaytree树模拟队列+离散化缩点
阅读量:4671 次
发布时间:2019-06-09

本文共 2550 字,大约阅读时间需要 8 分钟。

数据较大,需要先把每个top不会操作到的段缩成一个点,记录其开始和结束的位置,和top能操作到的点一起建立一颗伸展树模拟

然后就是普通的队列模拟操作

/*不会被top操作到的区间就缩点通过splay tree模拟出序列,初始序列的第i个缩点对应的树结点也是i操作top a:找到结点a,将其移到最左边query a:结点a的左边有多少人rank a:第a个结点是第几个结点*/#include
#include
#include
#include
#define maxn 100005#define L ch[r][0]#define R ch[r][1]using namespace std;int pre[maxn],ch[maxn][2],size[maxn],num[maxn],root,tot;int s[maxn],e[maxn],cnt; void debug();inline void newnode(int &r,int fa,int k){ r=k; ch[r][0]=ch[r][1]=0; pre[r]=fa; size[r]=num[r]=e[k]-s[k]+1;}inline void pushup(int r){ size[r]=size[L]+size[R]+num[r];}void build(int &x,int l,int r,int fa){ if(l>r) return; int mid=l+r>>1; newnode(x,fa,mid); build(ch[x][0],l,mid-1,x); build(ch[x][1],mid+1,r,x); pushup(x);}void init(int n){ root=tot=0; size[root]=pre[root]=ch[root][0]=ch[root][1]=0; build(root,1,n,0);}void Rotate(int x,int kind){ int y = pre[x]; //pushdown(y); //pushdown(x);//先把y的标记下传,在把x的标记下传 ch[y][!kind] = ch[x][kind]; pre[ch[x][kind]] = y; if(pre[y]) ch[pre[y]][ch[pre[y]][1]==y] = x; pre[x] = pre[y]; ch[x][kind] = y; pre[y] = x; pushup(y);}//Splay调整,将r结点调整到goal下面void splay(int r,int goal){ //push_down(r); while(pre[r] != goal) { if(pre[pre[r]] == goal) Rotate(r,ch[pre[r]][0]==r); else { int y = pre[r]; int kind = ch[pre[y]][0]==y; if(ch[y][kind] == r) { Rotate(r,!kind); Rotate(r,kind); } else { Rotate(y,kind); Rotate(r,kind); } } } pushup(r); if(goal == 0) root = r;} int getmin(int r){
while(L) r=L;return r;} void del(){ int t=root; if(ch[root][1]){ root=ch[root][1]; splay(getmin(root),0); ch[root][0]=ch[t][0]; if(ch[root][0]) pre[ch[root][0]]=root; } else root=ch[root][0]; pre[root]=0; pushup(root);} int Bin(int x){
//二分查找x属于那一段 int l=1,r=cnt; while(l<=r){ int mid=l+r>>1; if(s[mid]<=x && e[mid]>=x) return mid; if(x
0 && p[i]-p[i-1]>1){ cnt++; s[cnt]=p[i-1]+1; e[cnt]=p[i]-1; } cnt++; s[cnt]=p[i];e[cnt]=p[i]; } init(cnt); // debug(); printf("Case %d:\n",tt); for(int i=0;i

 

转载于:https://www.cnblogs.com/zsben991126/p/10006172.html

你可能感兴趣的文章
zoj 2112 树状数组 套主席树 动态求区间 第k个数
查看>>
4538: [Hnoi2016]网络
查看>>
186. [USACO Oct08] 牧场旅行
查看>>
一个屌丝程序猿的人生(三十九)
查看>>
Linux常用命令
查看>>
Spring之@Configuration配置解析
查看>>
Windows操作系统远程Linux服务器传输文件方法(以EasyDSS云平台、EasyNVR上传部署为例)...
查看>>
pip安装第三方库以及版本
查看>>
一、app更新提示后台接口开发-(2)数据库表设计
查看>>
利用data-src属性 更换图片
查看>>
Spring(3)
查看>>
SSM整合 mybatis多条件查询与分页
查看>>
VS2010中dumpbin工具的使用
查看>>
使用Golang搭建web服务
查看>>
HTML5触摸事件(touchstart、touchmove和touchend)
查看>>
架构师软技能之协商(上)
查看>>
商品翻牌效果(纯css)
查看>>
win10 UWP 序列化
查看>>
读书心得
查看>>
前端知识整理 CSS盒模型
查看>>