再刷水题我就废了。。。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define lc(x) ch[x][0]
#define rc(x) ch[x][1]
#define inf 0x3f3f3f3f
#define N 200005
using namespace std;
int ch[N][];
int k[N];int cnt,root;
int size[N],fa[N];
void push_up(int x)
{
size[x]=size[ch[x][]]+size[ch[x][]]+;
}
void rotate(int p)
{
int q=fa[p],y=fa[q],x=(p==ch[q][]);
ch[q][x]=ch[p][x^];fa[ch[q][x]]=q;
ch[p][x^]=q;fa[q]=p;
fa[p]=y;
if(y)
{
if(q==ch[y][])ch[y][]=p;
else ch[y][]=p;
}
push_up(q);push_up(p);
return ;
}
void splay(int x)
{
for(int y;y=fa[x];rotate(x))
{
if(fa[y])
{
if((ch[y][]==x&&ch[fa[y]][]==y)||(ch[y][]==x&&ch[fa[y]][]==y))rotate(y);
else rotate(x);
}
}
root=x;
}
int pre(int v)
{
int x=root;int tmp=-inf;
while(ch[x][k[x]<v])
{
if(k[x]<v)tmp=k[x];
x=ch[x][k[x]<v];
}if(k[x]<v)tmp=k[x];
return tmp;
}
int suc(int v)
{
int x=root;int tmp=inf;
while(ch[x][k[x]<=v])
{
if(k[x]>v)tmp=k[x];
x=ch[x][k[x]<=v];
}if(k[x]>v)tmp=k[x];
return tmp;
}
int find(int z)
{
int x=root;
if(k[x]==z)return x;
while(ch[x][k[x]<z])
{
x=ch[x][k[x]<z];
if(k[x]==z)return x;
}
return ;
}
void insert(int z)
{
int x=root;size[x]++;
while(ch[x][k[x]<z])x=ch[x][k[x]<z],size[x]++;
cnt++;ch[x][k[x]<z]=cnt;k[cnt]=z;size[cnt]=;fa[cnt]=x;splay(cnt);
}
void del(int x)
{
splay(x);
if(!ch[x][])
{
root=ch[x][];fa[ch[x][]]=;
}
else if(!ch[x][])
{
root=ch[x][];fa[ch[x][]]=;
}
else
{
fa[ch[x][]]=;int tmp=ch[x][];
while(ch[tmp][])tmp=ch[tmp][];
splay(tmp);ch[tmp][]=ch[x][];fa[ch[x][]]=tmp;
push_up(tmp);
}
return ;
}
int fd(int kk,int x)
{
int l=ch[kk][];int r=ch[kk][];
if(size[l]+==x)return k[kk];
if(size[l]>=x)return fd(l,x);
return fd(r,x-size[l]-);
}
int pr(int z)
{
int ans=;
int x=root;
while(x)
{
if(k[x]<=z)
{
ans+=size[ch[x][]]+;
x=ch[x][];
}
else x=ch[x][];
}
return ans;
}
void yu()
{
root=;k[]=inf;cnt=;size[]=;
insert(-inf);
}
int main()
{
yu();
int n;
scanf("%d",&n);
for(int o=;o<=n;o++)
{
int t1,t2;
scanf("%d%d",&t1,&t2);
if(t1==)
{
insert(t2);
}
else if(t1==)
{
int x1=find(t2);
if(x1!=)del(x1);
}
else if(t1==)
{
printf("%d\n",pr(t2-));
}
else if(t1==)
{
printf("%d\n",fd(root,t2+));
}
else if(t1==)
{
printf("%d\n",pre(t2));
}
else
{
printf("%d\n",suc(t2));
}
}
return ;
}

bzoj 3224 splay模板题4的更多相关文章

  1. bzoj 1588 splay模板题

    用晚自习学了一下splay模板,没想象中那么难,主要是左旋和右旋可以简化到一个函数里边,减少代码长度... #include<iostream> #include<cstdio> ...

  2. bzoj 3223 splay模板题3

    水题...貌似理解splay怎么维护数列了... 每个点维护一个size,它的位置就是它的size,区间翻转的话可以打标记,find的时候push_down,交换左右子树. #include<i ...

  3. bzoj 1208 splay模板题2

    自己yy了找前驱和后继,学了学怎么删除...(反正就是练模板) #include<iostream> #include<cstdio> #include<cstring& ...

  4. BZOJ 3224 平衡树模板题

    Treap: //By SiriusRen #include <cstdio> #include <algorithm> using namespace std; int n, ...

  5. 【BZOJ 3196】二逼平衡树 线段树套splay 模板题

    我写的是线段树套splay,网上很多人写的都是套treap,然而本蒟蒻并不会treap 奉上sth神犇的模板: //bzoj3196 二逼平衡树,支持修改某个点的值,查询区间第k小值,查询区间某个值排 ...

  6. 【BZOJ 3188】【Coci 2011】Upit Splay模板题

    转啊转终于转出来了,然而我的模板跟陈竞潇学长的模板一模一样,还是太弱啊,第一次用指针. #include<cstdio> #include<cstring> #include& ...

  7. BZOJ 1208 [HNOI2004]宠物收养所 | SPlay模板题

    题目: 洛谷也能评 题解: 记录一下当前树维护是宠物还是人,用Splay维护插入和删除. 对于任何一次询问操作都求一下value的前驱和后继(这里前驱和后继是可以和value相等的),比较哪个差值绝对 ...

  8. BZOJ 1588 平衡树 模板题

    Treap: //By SiriusRen #include <cstdio> #include <algorithm> using namespace std; int si ...

  9. PKU-3580 SuperMemo(Splay模板题)

    SuperMemo 题目链接 Your friend, Jackson is invited to a TV show called SuperMemo in which the participan ...

随机推荐

  1. 阿里云消息队列MQ_HTTP接入 for .NetCore 简单例子

    , , )).TotalMilliseconds;                 , , )).TotalMilliseconds;                 )                ...

  2. Kubernetes deployed on multiple ubuntu nodes

    This document describes how to deploy kubernetes on multiple ubuntu nodes, including 1 master node a ...

  3. Java命令行的执行参数

    Java 程序命令行参数说明 启动Java程序的方式有两种: # starts a Java virtual machine, loads the specified class, and invok ...

  4. Jersey the RESTful Web Services in Java

    Jersey 是一个JAX-RS的实现, JAX-RS即Java API for RESTful Web Services, 支持按照表述性状态转移(REST)架构风格创建Web服务. REST 中最 ...

  5. Asp.net NVelocity 模版引擎

    NVelocity.dll是Java中常用的一个模版,下面是常用的模版引擎 1,返回string类型的html代码 /// <summary> /// 获取html模版 /// </ ...

  6. css默认值汇总

    原文:http://www.cnblogs.com/xiangzi888/archive/2011/10/12/2209514.html HTML标签CSS属性默认值汇总 这个东西,在你需要还原默认值 ...

  7. [转]JS调用Android里面的方法,Android调用JS里面的方法

    FROM : http://blog.csdn.net/hj563308597/article/details/45197709 Android WebView 在公司Android的开发过程中遇到一 ...

  8. 在GoF设计模式

    在GoF设计模式中,结构型模式有: 1.适配器模式 Adapter   适配器模式是将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作.   ...

  9. 获取图片base64编码的几种方法

    前文中我们聊了 Data URI 和 base64编码,稍微回顾下.base64编码 是将数据用 64 个可打印的字符进行编码的方式,任何数据底层实现都是二进制,所以都可以进行 base64编码,ba ...

  10. Qt环境搭建(Qt Creator)+Visual Studio

    1.http://www.cnblogs.com/ranjiewen/p/5318768.html 简述 经常有人问我编写Qt程序时使用什么IDE,其实这个真的很难回答(各有所长),只能说看个人爱好了 ...