BZOJ 1503 郁闷的出纳员 (treap)
1503: [NOI2004]郁闷的出纳员
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 13370 Solved: 4808
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2
Sample Output
20
-1
2
HINT
Source
析:用treap 维护一个序列,用一个变量来记录全体人员加的工资和扣除的工资,对于每次扣除时,把一小于的最低工资的删除,很容易维护。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
//#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 1000;
const int maxm = 100 + 10;
const ULL mod = 10007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, -1, 0, 1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} int val, ans;
struct Node{
Node *ch[2];
int r, v, s;
Node(int vv) : v(vv) { ch[0] = ch[1] = 0; r = rand(); s = 1; }
bool operator < (const Node &rhs) const{
return r < rhs.r;
}
int cmp(int x) const{
if(x == v) return -1;
return x < v ? 0 : 1;
}
void maintain(){
s = 1;
if(ch[0]) s += ch[0]->s;
if(ch[1]) s += ch[1]->s;
}
}; 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;
} void insert(Node *&o, int x){
if(o == 0) o = new Node(x);
else{
int d = (x < o->v ? 0 : 1);
insert(o->ch[d], x);
if(o->ch[d]->r > o->r) rotate(o, d^1);
}
o->maintain();
} void del(Node *&o){
if(o == 0) return ;
++ans;
del(o->ch[0]);
del(o->ch[1]);
delete o;
o = 0;
} void remove(Node *&o, int x){
if(o == 0) return ;
while(o && x > o->v){
del(o->ch[0]);
if(o->ch[1]) rotate(o, 0);
else del(o);
}
if(o == 0) return ;
remove(o->ch[0], x);
o->maintain();
} int get_kth(Node *o, int k){
if(o == 0 || k <= 0 || k > o->s) return -1;
int s = o->ch[1] == 0 ? 0 : o->ch[1]->s;
if(k == s + 1) return o->v + val;
else if(k <= s) return get_kth(o->ch[1], k);
return get_kth(o->ch[0], k-s-1);
} Node *root; int main(){
srand(233333);
scanf("%d %d", &n, &m);
int x; root = 0;
char op[5]; while(n--){
scanf("%s %d", op, &x);
if(op[0] == 'I'){
if(x < m) continue;
insert(root, x - val);
}
else if(op[0] == 'A') val += x;
else if(op[0] == 'S'){
val -= x; x = m - val;
remove(root, x);
}
else printf("%d\n", get_kth(root, x));
}
printf("%d\n", ans);
return 0;
}
BZOJ 1503 郁闷的出纳员 (treap)的更多相关文章
- [BZOJ 1503]郁闷的出纳员(fhq treap)
[BZOJ 1503]郁闷的出纳员 题面 第一行有两个非负整数n和min.n表示下面有多少条命令,min表示工资下界. 接下来的n行,每行表示一条命令.命令可以是以下四种之一: 名称 格式 作用 I命 ...
- 洛谷 1486/BZOJ 1503 郁闷的出纳员
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 13866 Solved: 5069[Submit][Stat ...
- bzoj 1503郁闷的出纳员(splay)
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 11759 Solved: 4163[Submit][Stat ...
- BZOJ 1503 郁闷的出纳员
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...
- BZOJ 1503 郁闷的出纳员(平衡树)(NOI 2004)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作 ...
- BZOJ 1503 郁闷的出纳员(splay)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 题意:给出一个数列(初始为空),给出一个最小值Min,当数列中的数字小于Min时自动 ...
- bzoj 1503: [NOI2004]郁闷的出纳员 Treap
1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 6263 Solved: 2190[Submit][Statu ...
- [BZOJ1503] [NOI2004] 郁闷的出纳员 (treap)
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...
- BZOJ1503[NOI2004]郁闷的出纳员——treap
OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常调整员工的工资.如果他心 ...
随机推荐
- 用eclipse来运行带参数的命令行程序,配置命令行程序的参数
以上从网上找了点资料:右键点主类名 --> 运行--> 打开运行对话框--> Main(主类)--> 右边Arguments(参数) 点他以后然后在下面Program argu ...
- <script type="text/template">是干什么的,为什么要把html写在js中? 这是什么编程语言风格,都能这样用吗?
这一段存放了一个模板.在js里面,经常需要使用js往页面中插入html内容.比如这样: var number = 123; $('#d').append('<div class="t& ...
- linux之 multipath 多路径
一.什么是多路径 普通的电脑主机都是一个硬盘挂接到一个总线上,这里是一对一的关系.而到了有光纤组成的SAN环境,或者由iSCSI组成的IPSAN环境,由于主机和存储通过了光纤交换机或者多块网卡及IP来 ...
- Jenkins 基础入门
原文地址:Jenkins 基础入门 博客地址:http://www.extlight.com 一.前言 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作, ...
- hackerrank Week of Code 31
https://www.hackerrank.com/contests/w31/challenges Beautiful Word 模拟 Accurate Sorting 检查每个数字距离原位是否都不 ...
- bzoj4403 两个串
Description 兔子们在玩两个串的游戏.给定两个字符串S和T,兔子们想知道T在S中出现了几次, 分别在哪些位置出现.注意T中可能有“?”字符,这个字符可以匹配任何字符. Input 两行两个字 ...
- 简化Redis数据访问代码RedisTemplate
---恢复内容开始--- Redis数据结构简介: Redis可以存储键与5中数据结构类型之间的映射,这5中数据结构类型分别是;String(字符串),List(列表),Set(集合),Hash(散列 ...
- 最小化安装CentOS7,没有ifconfig命令---yum search command_name搜索未知包名
新安装的CentOS7系统,想查询ip的时候,发现没有ifconfig这个命令: -bash: ifconfig: 未找到命令 yum安装: 没有可用软件包 ifconfig 既然知道命令,搜索一下命 ...
- 解决Maven出现Plugin execution not covered by lifecycle configuration 错误
http://blog.163.com/xh_ding/blog/static/1939032892015222368827/ 解决Maven出现Plugin execution not covere ...
- 12步轻松搞定Python装饰器
译者:寒寻 译文:http://www.cnblogs.com/imshome/p/8327438.html 原文:https://dzone.com/articles/understanding-p ...