题目大意:

有一些员工 他们有工资 当他们的工资低于一个值时 他们会永远离开

I命令 I_k 新建一个工资档案,初始工资为k。
                如果某员工的初始工资低于工资下界,他将立刻离开公司。
A命令 A_k 把每位员工的工资加上k
S命令 S_k 把每位员工的工资扣除k
F命令 F_k 查询第k多的工资

支持以上四种操作 最后输出有多少个员工离开

思路:

几乎是splay裸题 对于A S操作维护一个变量即可

A S的时候find一下满足的最小值 转到根上 把左儿子扔掉

其他操作在剩下的树中搞即可

(那么多数据那么多询问 就错了一个 答案还差1)

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define inf 2139062143
#define ll long long
#define MAXN 300100
#define MOD 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,mn,w,sum;char Ch[];
int ch[MAXN][],fa[MAXN],tot,cnt[MAXN],val[MAXN],sz[MAXN],rt;
inline int which(int x) {return ch[fa[x]][]==x;}
inline void upd(int x) {if(x) sz[x]=sz[ch[x][]]+cnt[x]+sz[ch[x][]];}
inline void rotate(int x)
{
int f=fa[x],z=fa[f],k=which(x);
ch[f][k]=ch[x][k^],fa[ch[f][k]]=f,fa[f]=x,ch[x][k^]=f,fa[x]=z;
if(z) ch[z][f==ch[z][]]=x;upd(f);upd(x);return ;
}
inline void splay(int x)
{
for(int f;f=fa[x];rotate(x))
if(fa[f]) rotate(which(x)==which(f)?f:x);
rt=x;
}
inline void insert(int x)
{
int pos=rt,f;
while()
{
if(val[pos]==x) {sum++,cnt[pos]++;splay(pos);return ;}
f=pos,pos=ch[pos][val[pos]<x];
if(!pos)
{
pos=++tot,val[pos]=x,cnt[pos]=sz[pos]=,fa[pos]=f,sum++;
ch[f][val[f]<x]=pos,ch[pos][]=ch[pos][]=;upd(f);
splay(pos);return ;
}
}
}
inline void Insert(int x)
{
if(!rt) {sum++,val[++tot]=x,ch[tot][]=ch[tot][]=fa[tot]=,cnt[tot]=sz[tot]=,rt=tot;return;}
insert(x);
}
inline void Find(int x)
{
int res=,pos=rt;
while()
{
if(!pos)
{
if(res) {splay(res);ch[res][]=,fa[ch[res][]]=;upd(rt);}
else rt=;return ;
}
if(x<val[pos]) res=pos,pos=ch[pos][];
else
{
if(val[pos]==x) {splay(pos);ch[pos][]=,fa[ch[pos][]]=;upd(rt);return ;}
pos=ch[pos][];
}
}
}
int find_rank(int x)
{
int tmp=,pos=rt;
if(x>sz[rt]) return -w-;
else x=sz[rt]-x+;
while()
if(ch[pos][]&&x<=sz[ch[pos][]]) pos=ch[pos][];
else
{
tmp=sz[ch[pos][]]+cnt[pos];
if(x<=tmp) return val[pos];
x-=tmp,pos=ch[pos][];
}
}
int main()
{
n=read(),mn=read();int a;
for(int i=;i<=n;i++)
{
scanf("%s",Ch);a=read();
if(Ch[]=='I') {if(a<mn) continue;Insert(a-w);}
else if(Ch[]=='F') printf("%d\n",find_rank(a)+w+(sz[rt]==&&((find_rank(a)+w)==)));
else {w+=(Ch[]=='S'?-:)*a;Find(mn-w);}
}
printf("%d\n",sum-sz[rt]);
}

(镘太巨了 原来我这个菜鸡没有upd sz)

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define inf 2139062143
#define ll long long
#define MAXN 300100
#define MOD 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-;ch=getchar();}
while(isdigit(ch)) {x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,mn,w,sum;char Ch[];
int ch[MAXN][],fa[MAXN],tot,cnt[MAXN],val[MAXN],sz[MAXN],rt;
inline int which(int x) {return ch[fa[x]][]==x;}
inline void upd(int x) {if(x) sz[x]=sz[ch[x][]]+cnt[x]+sz[ch[x][]];}
inline void rotate(int x)
{
int f=fa[x],z=fa[f],k=which(x);
ch[f][k]=ch[x][k^],fa[ch[f][k]]=f,fa[f]=x,ch[x][k^]=f,fa[x]=z;
if(z) ch[z][f==ch[z][]]=x;upd(f);upd(x);return ;
}
inline void splay(int x)
{
for(int f;f=fa[x];rotate(x))
if(fa[f]) rotate(which(x)==which(f)?f:x);
rt=x;
}
inline void insert(int x)
{
int pos=rt,f;
while()
{
if(val[pos]==x) {sum++,cnt[pos]++;upd(pos);splay(pos);return ;}
f=pos,pos=ch[pos][val[pos]<x];
if(!pos)
{
pos=++tot,val[pos]=x,cnt[pos]=sz[pos]=,fa[pos]=f,sum++;
ch[f][val[f]<x]=pos,ch[pos][]=ch[pos][]=;upd(f);
splay(pos);return ;
}
}
}
inline void Insert(int x)
{
if(!rt) {sum++,val[++tot]=x,ch[tot][]=ch[tot][]=fa[tot]=,cnt[tot]=sz[tot]=,rt=tot;return;}
insert(x);
}
inline void Find(int x)
{
int res=,pos=rt;
while()
{
if(!pos)
{
if(res) {splay(res);ch[res][]=,fa[ch[res][]]=;upd(rt);}
else rt=;return ;
}
if(x<val[pos]) res=pos,pos=ch[pos][];
else
{
if(val[pos]==x) {splay(pos);ch[pos][]=,fa[ch[pos][]]=;upd(rt);return ;}
pos=ch[pos][];
}
}
}
int find_rank(int x)
{
int tmp=,pos=rt;
if(x>sz[rt]) return -w-;
else x=sz[rt]-x+;
while()
if(ch[pos][]&&x<=sz[ch[pos][]]) pos=ch[pos][];
else
{
tmp=sz[ch[pos][]]+cnt[pos];
if(x<=tmp) return val[pos];
x-=tmp,pos=ch[pos][];
}
}
int main()
{
n=read(),mn=read();int a;
for(int i=;i<=n;i++)
{
scanf("%s",Ch);a=read();
if(Ch[]=='I') {if(a<mn) continue;Insert(a-w);}
else if(Ch[]=='F') printf("%d\n",find_rank(a)+w);
else {w+=(Ch[]=='S'?-:)*a;Find(mn-w);}
}
printf("%d\n",sum-sz[rt]);
}

bzoj 1504 郁闷的出纳员的更多相关文章

  1. [BZOJ 1503]郁闷的出纳员(fhq treap)

    [BZOJ 1503]郁闷的出纳员 题面 第一行有两个非负整数n和min.n表示下面有多少条命令,min表示工资下界. 接下来的n行,每行表示一条命令.命令可以是以下四种之一: 名称 格式 作用 I命 ...

  2. bzoj 1503郁闷的出纳员(splay)

    1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 11759  Solved: 4163[Submit][Stat ...

  3. BZOJ 1503 郁闷的出纳员 (treap)

    1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 13370  Solved: 4808[Submit][Stat ...

  4. 洛谷 1486/BZOJ 1503 郁闷的出纳员

    1503: [NOI2004]郁闷的出纳员 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 13866  Solved: 5069[Submit][Stat ...

  5. BZOJ 1503 郁闷的出纳员

    Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...

  6. BZOJ 1503 郁闷的出纳员(平衡树)(NOI 2004)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作 ...

  7. BZOJ 1503 郁闷的出纳员(splay)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 题意:给出一个数列(初始为空),给出一个最小值Min,当数列中的数字小于Min时自动 ...

  8. BZOJ[NOI2004]郁闷的出纳员 | Splay板子题

    题目: 洛谷也能评测....还有我wa了10多次的记录233 题解: 不要想得太复杂,搞一个全局变量记录一下工资的改变量Delta,这样可以等询问的时候就输出val+Delta,然后插入的时候插入x- ...

  9. 【BZOJ】【1503】 【NOI2004】郁闷的出纳员

    Splay Splay的模板题吧……妥妥的序列操作= =(好像有段时间没写过这种纯数据结构题了……) /************************************************ ...

随机推荐

  1. Mac安装Protobuf

    1. 下载protobuf2.6.1:https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz ...

  2. ZOJ - 3781 Paint the Grid Reloaded 题解

    题目大意: 给一个n*m的X O构成的格子,对一个点操作可以使与它相连通的所有一样颜色的格子翻转颜色(X—>O或O—>X),问给定的矩阵最少操作多少次可以全部变成一样的颜色. 思路: 1. ...

  3. Codeforces225E - Unsolvable

    Portal Description 求所有对于方程\[z=\left \lfloor \frac{x}{2} \right \rfloor+y+xy\]不存在正整数解\((x,y)\)的\(z\)中 ...

  4. 【数学】codeforces A. Success Rate

    http://codeforces.com/contest/773/problem/A [思路] 用 (x+a)/(y+b) = p/q 来表示其核心思想,其中a 为做对的题目,b为做的题目,则有x+ ...

  5. 通过一个用户管理实例学习路由react-router-dom知识

    我们通过一个用户管理实例来学习react-router-dom 这个实例包括9个小组件 App.js 引入组件 Home.js 首页组件 User.js 用户管理组件 -  UserList.js 用 ...

  6. 【BZOJ4517】排列计数(排列组合)

    题意:1-n的一个序列,其中有m个a[i]=i,求方案数 n,m<=1000000 题意:显然ANS=c(n,m)*d[n-m] d[i]为错排方案数=d[i-1]*n+(-1)^n ; ..] ...

  7. C#高级编程第9版 第二章 核心C# 读后笔记

    System命名空间包含了最常用的.NET类型.对应前面第一章的.NET基类.可以这样理解:.NET类提供了大部分的功能,而C#语言本身是提供了规则. pseudo-code,哈哈,秀逗code.伪代 ...

  8. Jupyter Notebook 基本使用

    Jupyter 官网 IPython Interactive Computing IPython Notebook使用浏览器作为界面,向后台的IPython服务器发送请求,并显示结果.在浏览器的界面中 ...

  9. 【c++】c++一些基础面试题

    http://www.mianwww.com/html/2013/10/19128.html http://blog.csdn.net/wdzxl198/article/details/9050751 ...

  10. linux 查找目录下的文件内容并替换(批量)

    2.sed和grep配合 命令:sed -i s/yyyy/xxxx/g `grep yyyy -rl --include="*.txt" ./` 作用:将当前目录(包括子目录)中 ...