Ps:splay still can't write right at once. Always write a problem, really drunk drunk drunk ...
The difficulty lies in the change in wages, we only need to change the wage k, indicating that wages are now increased by K. Then if an employee comes in and "comes in, the initial wage is higher than the minimum wage," then we add the employee's salary, minus the value of k, to the balance tree.
Delete the person's time, as long as the "initial wage + wage change K" small numbers are all deleted. There is no need to delete a single, most of the balance tree will support the deletion of the whole tree operation of the ~ directly to the small value of the whole tree is deleted.
#include <iostream> #include <cstdio> #include <cstdlib> using namespace std;
const int maxint = 0x7fffffff;
struct Node {node *c[2];
int key;
int size;
Node () {key = size = 0;
C[0] = c[1] = this;
} node (int key_, node *c0, node *c1) {KEY = Key_;
C[0] = C0;
C[1] = C1; } node* RZ () {return size = c[0]->size + c[1]->size + 1, this;}}
Tnull, *null = &Tnull;
struct Splay {node *root;
Splay () {root = (new node (*null))-RZ ();
Root-key = Maxint;
} inline void Zig (int d) {node *t = root-c[d];
Root-c[d] = null-C[D];
null-c[d] = root;
root = t;
} inline void Zigzig (int d) {node *t = root, C[d], c[d];
Root, C[d], c[d] = null, c[d];
null-c[d] = root-c[d];
Root, c[d] = null, C[d], c[!d];
Null-C[D]-c[!d] = RZ ()
root = t; } inline void finish (int d) {node *t = null, C[d], *p = root-&Gt
C[!D];
while (t! = null) {T = null, C[D], c[d];
Null-C[D]-c[d] = p;
p = null-c[d]-RZ ();
null-c[d] = t;
} root-c[!d] = p;
} inline void Select (int k) {int t;
while (1) {bool d = k > (t = root-c[0]->size);
if (k = = T | | root, c[d] = = null) break;
if (d) k-= t+ 1;
BOOL DD = k > (t = root, C[d, c[0], size);
if (k = = T | | Root, c[d, c[dd] = = null) {Zig (d); break;}
if (DD) k-= t+1; D! = dd?
Zig (d), Zig (DD): Zigzig (d);
} finish (0), Finish (1);
Root-RZ ();
} inline void Search (int x) {while (1) {bool d = x > Root-key;
if (root-c[d] = = null) break;
BOOL DD = x > Root, C[d], key;
if (Root-c[d], c[dd] = = null) {Zig (d); break;} D! = dd?
Zig (d), Zig (DD): Zigzig (d);
} finish (0), Finish (1);
Root-RZ (); if (x > Root, Key) Select (Root-c[0)Size + 1);
} inline void ins (int x) {search (x);
Node *oldroot = root;
Root = new node (x, Oldroot-c[0], oldroot);
Oldroot-c[0] = null;
Oldroot, RZ ();
Root-RZ ();
} inline void del (int x) {search (x);
Node *oldroot = root;
root = root-c[1];
Select (0);
Root, c[0] = Oldroot, c[0];
Root-RZ ();
Delete Oldroot;
} int sel (int k) {return Select (k-1), Root->key;} int ran (int x) {return search (x), root-c[0], size + 1;}}
Sp
int limit, n;
int main () {scanf ("%d%d", &n, &limit);
char flag;
int tmp, biandong=0;
int away = 0;
while (n--) {scanf ("\n%c%d", &flag, &tmp);
if (flag = = ' I ') {tmp-= limit; if (TMP < 0)//The salary given at the beginning is less than {/*. For Mao it doesn't count to leave the company. "He would immediately leave the company angrily" is not "the total number of employees who leave the company". Because he doesn't count as an employee.
*///++away;
Continue
} sp.ins (tmp + biandong);
} if (flag = = = ' A ') biandong-= tmp; if (flag = = ' S ') {Biandong + = tmp;
Sp.ran (Biandong);
Away + = Sp.root, c[0], size;
Sp.root-c[0] = null;
Sp.root, RZ ();
} if (flag = = ' F ') {if (tmp > Sp.root-size-1) {printf (" -1\n");
Continue
} printf ("%d\n", Sp.sel (Sp.root-size-tmp) + Limit-biandong);
}} printf ("%d\n", Away);
return 0;
}