调了好久,发现两个问题:
首先插入的时候忘记把p赋给fa的孩子,还有就是pushup的时候加上一个判断
#include #include #include #include #include #include #include #include #include #include #include #define Key_value ch[ch[root][1]][0] using namespace std; const int maxn=100010; const int INF=1000000000; int N,M; int res; int ch[maxn][2],pre[maxn],size[maxn],key[maxn]; int root,tot1,tot2,s[maxn]; int det; void NewNode(int &r,int f,int val) {if(tot2)r=s[tot2--];else r=++tot1;ch[r][0]=ch[r][1]=0;pre[r]=f;key[r]=val;size[r]=1; } void pushup(int r) {if(r)//加了这个就对了size[r]=size[ch[r][0]]+size[ch[r][1]]+1; } void Rotate(int x,int kind) {int y=pre[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); } void Splay(int r,int goal) {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 get_kth(int r,int k) {int t=size[ch[r][0]]+1;if(t==k)return r;if(t>k)return get_kth(ch[r][0],k);return get_kth(ch[r][1],k-t); } void debug(int r) {if(!r)return;printf("%d**%d**%d**%d\n",key[r],r,ch[r][0],ch[r][1]);debug(ch[r][0]);debug(ch[r][1]); } int Insert(int x) {int p=root,fa=0;while(p){if(key[p]>=x)fa=p,p=ch[p][0];else fa=p,p=ch[p][1];}NewNode(p,fa,x);if(key[fa]=M){Insert(k-det);}else if(op[0]=='A')Increase(k);else if(op[0]=='S')Decrease(k);else if(op[0]=='F')Find(k);}printf("%d\n",res);return 0; }
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
Duilib中list控件支持ctrl和shif多行选中的实现
[ICML2015]Batch Normalization:Accelerating Deep Network Training by Reducing Internal Covariate Shif
win10系统 微软输入法 于eclipse ctrl+shif+f冲突间接处理办法
Codeforces Round #259 (Div. 2) B. Little Pony and Sort by Shif
读LDD3,内存映射与DMA--PAGE_SHIF…
VMware虚拟机安装XP【要先分区,再设置BOOT 启动CD,shif+上移】
更换iBus五笔的左与右Shif
sublime ctrl+shif+f 没用解决办法
idea 对 ctrl + z 的撤销 是 ctrl + shif + z
计算机最早的设计师应用于,计算机应用基础选择题doc.doc
win10自带截图神器:Win+Shift+S
Python基础之文件目录操作
python简述目录_Python基础之文件目录操作(示例代码)
tp5 如何做数据采集
任务2-7(服务器字体+阿里巴巴矢量库)
html标签(1):h1~h6,p,br,pre,hr
TI 电量计介绍与芯片选型指南
几款TI电源芯片简介
TI DSP芯片C2000系列读取FLASH数据
德州仪器(Ti)平台嵌入式开发基础
TI三相电机智能栅极驱动芯片特点分类
省选模拟(12.08) T3 圈圈圈圈圈圈圈圈
Hadoop生态圈技术栈(上)
大数据开发基础入门与项目实战(三)Hadoop核心及生态圈技术栈之6.Impala交互式查询
小猿圈之Linux下Mysql 操作命令
大数据Hadoop生态圈常用面试题
大数据开发基础入门与项目实战(三)Hadoop核心及生态圈技术栈之4.Hive DDL、DQL和数据操作
备战Noip2018模拟赛11(B组)T3 Monogatari 物语
【智能优化算法-圆圈搜索算法】基于圆圈搜索算法Circle Search Algorithm求解单目标优化问题附matlab代码
NYOJ 78 圈水池
递归问题 跑道 汽车 绕圈问题 Python实现
Hadoop生态圈(三):MapReduce
微信公众账号
微信扫一扫加关注