BZOJ1503——郁闷的出纳员
1、题目大意:一道treap题,支持插入,询问第K大,还有全体修改+上一个值,如果某个点值小于x,那么就删除这个点
插入100000次,询问100000次,修改100次。。最后输出删了多少个点
2、分析:首先看修改是100次的,我就没有多想什么lazy,什么的
就是名次树,修改的话,我们就遍历treap,全部修改我们就O(n)搞一下
最后说一个坑爹的地方,就是插入前就否认的点不算T_T
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node{
Node* ch[2];
int r, v, s, c;
inline bool operator < (const Node& rhs) const{
return r < rhs.r;
}
inline int cmp(int x){
if(x == v) return -1;
if(x < v) return 0;
return 1;
}
inline void maintain(){
s = c;
if(ch[0] != NULL) s += ch[0] -> s;
if(ch[1] != NULL) s += ch[1] -> s;
return;
}
};
Node ft[500000];
struct treap{
Node *p;
int cnt;
inline void init(){
cnt = -1;
p = NULL;
return;
}
inline void rotate(Node* &o, int d){
Node *k = o -> ch[d ^ 1];
o -> ch[d ^ 1] = k -> ch[d];
k -> ch[d] = o;
o -> maintain();
k -> maintain();
o = k;
return;
}
inline void insert(Node* &o, int x){
if(o == NULL){
o = &ft[++ cnt];
o -> ch[0] = o -> ch[1] = NULL;
o -> v = x;
o -> r = rand();
o -> c = 1;
}
else if(o -> v == x) o -> c ++;
else{
int d = o -> cmp(x);
insert(o -> ch[d], x);
if(o -> ch[d] -> r > o -> r) rotate(o, d ^ 1);
}
o -> maintain();
return;
}
inline void A(Node* &o, int x){
if(o == NULL) return;
o -> v += x;
A(o -> ch[0], x);
A(o -> ch[1], x);
return;
}
inline void S(Node* &o, int x){
while(o != NULL && o -> v < x) o = o -> ch[1];
if(o == NULL) return;
if(o -> ch[0] != NULL) S(o -> ch[0], x);
if(o -> ch[1] != NULL) S(o -> ch[1], x);
if(o != NULL) o -> maintain();
return;
}
inline int k_th(Node* &o, int k){
int ls = 0, rs = 0;
if(o -> ch[0] != NULL) ls = o -> ch[0] -> s;
if(ls >= k) return k_th(o -> ch[0], k);
else if(ls + o -> c >= k) return o -> v;
else return k_th(o -> ch[1], k - ls - o -> c);
}
} wt;
int main(){
int n, m, orz = 0;
scanf("%d%d", &n, &m);
wt.init();
for(int i = 1; i <= n; i ++){
char str[5]; int k;
scanf("%s%d", str, &k);
if(str[0] == 'I'){
if(k >= m){
orz ++;
wt.insert(wt.p, k);
}
}
else if(str[0] == 'A') wt.A(wt.p, k);
else if(str[0] == 'F'){
if(wt.p == NULL || k > wt.p -> s) printf("-1\n");
else printf("%d\n", wt.k_th(wt.p, wt.p -> s - k + 1));
}
else {
wt.A(wt.p, -k);
wt.S(wt.p, m);
}
}
printf("%d\n", orz - wt.p -> s);
return 0;
}
BZOJ1503——郁闷的出纳员的更多相关文章
- bzoj1503 郁闷的出纳员
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的 工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经 ...
- [BZOJ1503]郁闷的出纳员(Splay)
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...
- bzoj1503 郁闷的出纳员 splay版
自己yy的写法 可能有点奇怪吧 详情看代码 还是蛮短的 #include<cstdio> #include<cstring> #include<algorithm> ...
- bzoj1503 郁闷的出纳员(平衡树,思维)
题目大意: 现在有n个操作和一个最低限度m \(I\)命令\(I\ k\)新建一个工资档案,初始工资为k. \(A\)命令$A\ k $把每位员工的工资加上k \(S\)命令$S\ k $把每位员工的 ...
- [BZOJ1503][NOI2004]郁闷的出纳员
[BZOJ1503][NOI2004]郁闷的出纳员 试题描述 OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是 ...
- bzoj1503 [NOI2004]郁闷的出纳员(名次树+懒惰标记)
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 8705 Solved: 3027[Submit][Statu ...
- [BZOJ1503][NOI2004]郁闷的出纳员 无旋Treap
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MB Description OIER公司是一家大型专业化软件公司,有着数以万计的员 ...
- 【bzoj1503】[NOI2004]郁闷的出纳员
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 13890 Solved: 5086[Submit][Stat ...
- bzoj1503: [NOI2004]郁闷的出纳员(伸展树)
1503: [NOI2004]郁闷的出纳员 题目:传送门 题解: 修改操作一共不超过100 直接暴力在伸展树上修改 代码: #include<cstdio> #include<cst ...
随机推荐
- SVM支持向量机的高维映射与核函数-记录毕业论文2
上一篇博客将了在数据集线性可分的情况下的支持向量机,这篇主要记录如何通过映射到高维解决线性不可分的数据集和如何通过核函数减少内积计算量的理论思想. [5]径向基函数的核函数:https://www.q ...
- 转:遗传算法解决TSP问题
1.编码 这篇文章中遗传算法对TSP问题的解空间编码是十进制编码.如果有十个城市,编码可以如下: 0 1 2 3 4 5 6 7 8 9 这条编码代表着一条路径,先经过0,再经过1,依次下去. 2.选 ...
- easyUI datagrid学习笔记
1.easyUI表格的列属性 formatter:function(value,rowdata,rowindex) { return '['+value+']';//格式化,给每个值加上'[]': } ...
- C# Language Specification
https://msdn.microsoft.com/en-us/library/aa645596(v=vs.71).aspx
- 2012 Theory for Forward Rendering
http://miss-cache.blogspot.com/2012/08/lighting-transparent-surfaces-with_26.html http://aras-p.info ...
- ecshop 订单编号 get_order_sn
文件地址include/lib_order.php ,要引用需要先导入 lib_order.php require_once(ROOT_PATH . 'includes/lib_order.php') ...
- HBase中的压缩算法比较 GZIP、LZO、Zippy、Snappy [转]
网址: http://www.cnblogs.com/panfeng412/archive/2012/12/24/applications-scenario-summary-of-compressio ...
- Map静态键值对
private final static Map<String,String> map = new HashMap<String, String>(); static { // ...
- Security Test Cases
https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents Username Enumeration Vulner ...
- php/js互传cookie中文乱码的问题
问题发现: 过去好好的,今天突然网页出现了问题. 在猎豹和IE都出现问题,在360浏览器就正常. 经过排错,最终发现: js存储cookie,php读取的时候成了乱码 . 问题分析: 这是因为文字编 ...