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 ...
随机推荐
- [NOIP2014] 解方程&加强版 (bzoj3751 & vijos1915)
大概有$O(m)$,$O(n\sqrt{nm})$,$O(n\sqrt{m})$的3个算法,其中后2个可以过加强版.代码是算法3,注意bzoj的数据卡掉了小于20000的质数. #include< ...
- Processing Images
https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_ ...
- 整数分解 && 质因数分解
输入整数(0-30)分解成所有整数之和.每四行换行一次. 一种方法是通过深度优先枚举出解.通过递归的方式来实现. #include <stdio.h> #include <strin ...
- 关键词提取1-C#
C# 中文分词算法(实现从文章中提取关键字算法) using System;using System.IO;using System.Text;using System.Collections;usi ...
- 多日期选择jQuery插件 MultiDatesPicker for jQuery UI
Multiple-Dates-Picker-for-jQuery-UI是一个多日期选择的jquery控件. GIT源码: https://github.com/dubrox/Multiple-Da ...
- css让图片作为按钮的背景并且大小合适
最近在做ASP大作业,在做html页面的时候想把一个图片作为按钮的背景,搞了好久终于在csdn上找到了满意的答案: background-size: cover; 只需要这一句就ok了,就是这么简答. ...
- Occlusion Culling
遮挡剔除 http://www.bjbkws.com/online/1092/ unity遮挡剔除(应用) http://www.unitymanual.com/thread-37302-1-1.ht ...
- 常用的JS HTML DOM 事件
HTML DOM 事件 HTML DOM 事件允许Javascript在HTML文档元素中注册不同事件处理程序. 事件通常与函数结合使用,函数不会在事件发生前被执行! (如用户点击按钮). 提示: 在 ...
- Yii2 事务
$transaction = $connection->beginTransaction(); try { // ... executing other SQL statements ... $ ...
- jquery取消选择select下拉框
有三个select下拉框一个大类,两个小类隐藏,需要在选择大类的时候,小类显示同时清除另外的小类选择的项这需求有点儿.......... 下面是三个select: <select name=&q ...