题目来源:http://www.lydsy.com/JudgeOnline/problem.php?id=1503
1、首先,维护一个全局变量del,表示全局加多少。插入时要减去del,查找时要加上del,仔细领会一下。
2、删除时,找到工资比最低限小的工资最高的工人,把他旋转到根,然后删除他和左子树!
3、这题的查找是第K大,而不是第K小,要注意第K大的写法。
4、坑!这题说如果一个工人的初始工资比最低限小,那他就会立即离开,这个离开的工人就当是被UFO抓走了,不算在离开的工人之列!
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=101000;
int n,del=0,low;
int leave=0;
struct Splay {
int ch[N][2],f[N],root,cnt;
int a[N],c[N],s[N];
int grow (int k,int fa) {
int x=++cnt;
a[x]=k,s[x]=c[x]=1;
ch[x][0]=ch[x][1]=0;
f[x]=fa;
return x;
}
void pushup (int x) {
s[x]=s[ch[x][0]]+s[ch[x][