题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1503

题解:

维护一颗Splay和一个外部变量,树中每个节点表示一个人,节点权值a + 外部变量delta = 该员工工资。

细节看代码。

注意:一进来工资就低于最低工资的人不能算是“离开公司”的人。

 #include <cstdio>
#define fprintf(...)
#define maxn 100100 struct Splay {
int key[maxn], pre[maxn], son[maxn][], siz[maxn], ntot, root;
int trash[maxn], rtot; Splay():ntot(),root(),rtot(){}
void update( int nd ) {
siz[nd] = siz[son[nd][]] + siz[son[nd][]] + ;
}
void rotate( int nd, int d ) {
int p = pre[nd];
int s = son[nd][!d];
int ss = son[s][d]; if( p ) son[p][ nd==son[p][] ] = s;
else root = s;
son[nd][!d] = ss;
son[s][d] = nd; if( ss ) pre[ss] = nd;
pre[nd] = s;
pre[s] = p; update( nd );
update( s );
}
void splay( int nd, int top= ) {
while( pre[nd]!=top ) {
int p = pre[nd];
int nl = nd==son[p][];
if( pre[p]==top ) {
rotate( p, nl );
} else {
int pp = pre[p];
int pl = p==son[pp][];
if( nl==pl ) {
rotate( pp, pl );
rotate( p, nl );
} else {
rotate( p, nl );
rotate( pp, pl );
}
}
}
}
int newnode( int k, int p ) {
int nd;
if( rtot ) nd = trash[rtot--];
else nd = ++ntot;
key[nd] = k;
pre[nd] = p;
son[nd][] = son[nd][] = ;
siz[nd] = ;
return nd;
}
void insert( int k ) {
fprintf( stderr, "insert(%d)\n", k );
if( !root ) {
root = newnode( k, );
return;
}
int nd = root;
while( son[nd][ k<key[nd] ] )
nd = son[nd][ k<key[nd] ];
son[nd][ k<key[nd] ] = newnode( k, nd );
update( nd );
splay( nd, );
}
void erase_subtree( int nd ) {
fprintf( stderr, "erase_subtree(%d)\n", nd );
if( !nd ) return;
erase_subtree( son[nd][] );
erase_subtree( son[nd][] );
trash[++rtot] = nd;
}
void erase( int k ) {
fprintf( stderr, "erase(%d)\n", k );
int nd = root;
int active = nd;
while( nd ) {
if( key[nd]<=k ) {
int p = pre[nd];
int ls= son[nd][]; if( p ) son[p][ nd==son[p][] ] = son[nd][];
else root = son[nd][];
pre[son[nd][]] = p; pre[nd] = ;
son[nd][] = ; erase_subtree( nd ); if( p ) update( p );
nd = ls;
} else {
active = nd;
nd = son[nd][];
}
}
splay(active);
}
int nth( int n ) {
fprintf( stderr, "nth(%d)\n", n );
int nd = root;
while() {
int ls = siz[son[nd][]];
if( n<=ls ) {
nd=son[nd][];
} else if( n>=ls+ ) {
nd=son[nd][];
n -= ls+;
} else
break;
}
splay( nd );
return key[nd];
}
void print( int nd ) {
if(!nd) return;
print( son[nd][] );
fprintf( stderr, "%d %d %d %d %d\n", nd, pre[nd], son[nd][], son[nd][],
key[nd] );
print( son[nd][] );
}
}; Splay T;
int n, delta, limit, cnt; int main() {
//freopen( "input", "r", stdin );
scanf( "%d%d", &n, &limit );
delta = ;
cnt = ;
while(n--) {
char ch[];
int k;
scanf( "%s%d", ch, &k );
switch(ch[]) {
case 'I':
if( k<limit ) break;
cnt++;
k -= delta;
T.insert( k );
break;
case 'A':
delta += k;
break;
case 'S':
delta -= k;
T.erase( limit-delta- );
break;
case 'F':
if( !(<=k && k<=T.siz[T.root]) ) printf( "-1\n" );
else printf( "%d\n", T.nth(k)+delta );
break;
}
fprintf( stderr, "delta=%d\n", delta );
//T.print( T.root );
fprintf( stderr, "\n" );
}
printf( "%d\n", cnt-T.siz[T.root] );
}

bzoj1503 Splay 维护名次数,支持删除的更多相关文章

  1. 【BZOJ 3729】3729: Gty的游戏 (Splay维护dfs序+博弈)

    未经博主同意不得转载 3729: Gty的游戏 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 448  Solved: 150 Description ...

  2. HNOI2004宠物收养所(splay维护二叉搜索树模板题)

    描述 最近,阿Q开了一间宠物收养所.收养所提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物.每个领养者都希望领养到自己满意的宠物,阿Q根据领养者的要求通过他自己发明的一个特殊的公式,得出该领 ...

  3. Box HDU - 2475 (Splay 维护森林)

    Box \[ Time Limit: 5000 ms \quad Memory Limit: 32768 kB \] 题意 给出 \(n\) 个箱子的包含关系,每次两种操作. 操作 \(1\):把 \ ...

  4. iOS 限制TextField输入长度(支持删除)

    if (textField == _phoneTF) { //支持删除 && ) { return YES; } ) { _phoneTF.text = [textField.text ...

  5. BZOJ 3729 splay维护DFS序+博弈论

    思路: 这像是 阶梯Nim之类的东西 我们 直接把sg函数 设成mod(L+1)的 一棵子树 向下的奇数层上的石子xor起来 就是答案 有加点和改值的操作 就splay维护一下 //By Sirius ...

  6. BZOJ 1492 [NOI2007]货币兑换Cash (CDQ分治/splay 维护凸包)

    题目大意:太长了略 splay调了两天一直WA弃疗了 首先,我们可以猜一个贪心,如果买/卖,就一定都买/卖掉,否则不买/卖 反正货币的行情都是已知的,没有任何风险,所以肯定要选择最最最优的方案了 容易 ...

  7. BZOJ 1251 Splay维护序列

    思路: splay维护序列的裸题 啊woc调了一天 感谢yzy大佬的模板-- //By SiriusRen #include <cstdio> #include <cstring&g ...

  8. BZOJ1014[JSOI2008]火星人prefix(splay维护hash)

    Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...

  9. bzoj3786星系探索(splay维护dfs序)

    Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均有且仅有一个依赖星球.主星球 ...

随机推荐

  1. 1 - django-介绍-MTV-命令-基础配置-admin

    目录 1 什么是web框架 2 WSGI 3 MVC与MTV模式 3.1 MVC框架 3.2 MTV框架 3.3 区别 4 django介绍 4.1 Django处理顺序 4.2 创建django站点 ...

  2. 【Python项目】爬取新浪微博个人用户信息页

    微博用户信息爬虫 项目链接:https://github.com/RealIvyWong/WeiboCrawler/tree/master/WeiboUserInfoCrawler 1 实现功能 这个 ...

  3. linux下定时器介绍1

    POSIX Timer 间隔定时器 setitimer 有一些重要的缺点,POSIX Timer 对 setitimer 进行了增强,克服了 setitimer 的诸多问题: 首先,一个进程同一时刻只 ...

  4. SQl 跨服务器查询脚本示例

    1.采用OPENDATASOURCE select top 10 *from OPENDATASOURCE('SQLOLEDB','Data Source=IP地址;User ID=连接用户名称;Pa ...

  5. java四舍五入BigDecimal和js保留小数点两位

    java四舍五入BigDecimal保留两位小数的实现方法: // 四舍五入保留两位小数System.out.println("四舍五入取整:(3.856)="      + ne ...

  6. python网络编程--进程池

    一:进程池 进程池内部维护一个进程序列,当使用时,则去进程池中获取一个进程, 如果进程池序列中没有可供使用的进进程,那么程序就会等待,直到进程池中有可用进程为止. 进程池中有两个方法: apply a ...

  7. 洛谷P3385负环

    传送门 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...

  8. ubuntu12.04安装ruby2.3

    为了搭建github-pages博客,而github-pages后端依赖于ruby,且对版本有严格要求,自己尝试了各种姿势升级ruby2.3无果,最终在查阅了各种资料之后找到一个可行方案. icebu ...

  9. python_接口自动化测试框架

    本文总结分享介绍接口测试框架开发,环境使用python3+selenium3+unittest+ddt+requests测试框架及ddt数据驱动,采用Excel管理测试用例等集成测试数据功能,以及使用 ...

  10. Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))

    题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...