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 ...
随机推荐
- KEGG and Gene Ontology Mapping in Bioinformatic Method
使用KOBAS进行KEGG pathway和Gene Ontology分析 Article from Blog of Alfred-Feng http://blog.sina.com.cn/u/170 ...
- Python实现打印二叉树某一层的所有节点
不多说,直接贴程序,如下所示 # -*- coding: utf-8 -*- # 定义二叉树节点类 class TreeNode(object): def __init__(self,data=0,l ...
- Python字典和集合
Python字典操作与遍历: 1.http://www.cnblogs.com/rubylouvre/archive/2011/06/19/2084739.html 2.http://5iqiong. ...
- 9月22日上午JavaScript----window对象
window对象 window属性: opener:打开当前窗口的源窗口,如果这个窗口是由别的网页点击链接跳转过来的,或者是从另外一个页面点击打开窗口打开的,opener就是找到源页面的.如果当前窗口 ...
- C#读取Excel,DataTable取值为空的解决办法
连接字符串这么些就行了 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + opnFileName ...
- JavaScript学习笔记——对象分类
对象的分类 一.对象的分类 1.内置对象 Global Math 2.本地对象 Array Number String Boolean Function RegExp 3.宿主对象 DOM BOM 二 ...
- ecshop 订单-》订单状态
/** * 取得状态列表 * @param string $type 类型:all | order | shipping | payment */ function get_status_list($ ...
- centos 7 DenyHosts 安装 防暴力破解ssh登陆
为了减少软件扫描ssh登陆 还是用这个比较好点 默认端口号22 也要改 登陆密码也不要使用 弱口令 123456 这样的 Description DenyHosts is a python prog ...
- EF: Raw SQL Queries
Raw SQL Queries Entity Framework allows you to query using LINQ with your entity classes. However, t ...
- python内置函数每个执行一次
open # with open('log','r') as f: 或者 r=open(filename,r+) with open ('1.txt','r',encoding ...