$Splay $ template title.
Review the template for the stretch tree.
For the reduction of wages after the deletion of staff operations, I choose to insert a $min+delta_{reduced wage}$ node, $splay$ it to the root, cut off its own and left subtree, preserving the right subtree, so that the staff will disappear from the world.
#include <cstdio> #include <cstring> #include <algorithm> #define READ (x) x = Getint () using namespace Std;struct Node {node *ch[2], *fa;int D, SZ, sum, Lazy;bool pl () {return this->fa->ch[1] = = this; void SetC (node *r, bool c) {Ch[c] = r; r->fa = this;} void count () {sum = ch[0]->sum + Ch[1]->sum + sz;} void push () {if (lazy! = 0) {Ch[0]->lazy + = Lazy;ch[1]->lazy + lazy;ch[0]->d + lazy;ch[1]->d + = Lazy;lazy = 0;}}} *root, *null;node pool[100003];int top = 0, M, n, gone = 0;namespace splay{void Build () {null = &pool[0];null->d = Null->sz = Null->sum = 0;null->ch[0] = null->ch[1] = NULL->FA = null; ROOT = null;} Node *newnode () {node *t = &pool[++top];t->d = T->sz = T->sum = 0;t->ch[0] = t->ch[1] = T->FA = null ; return t;} void Rotate (node *r) {Node *f = r->fa; if (r = = NULL | | f = = NULL) Return;bool c = R->PL (); if (F->FA = = null) ROO T = r, R->fa = Null;else f->fa->setc (r, F->PL ()); F->seTC (R->CH[!C], c); R->setc (f,!c); F->count ();} void Update (node *r) {if (r! = ROOT) update (R->FA); R->push ();} void splay (node *r, node *tar = null) {update (R); for (; R->fa! = tar; rotate (R)) if (R->fa->fa = tar) rotate (r-> ;p L () = = R->FA->PL ()? R->FA:R); R->count ();} void ins (int num) {if (root = = null) {root = NewNode (); Root->d = num; Root->sz = Root->sum = 1;return;} Node *r = root;while (1) {r->push (); int k = r->d; bool C;if (num < k) C = 0;else if (num > k) c = 1;else {++r- >sz; ++r->sum; Splay (R); return;} if (r->ch[c] = = null) {R->ch[c] = NewNode () r->setc (R->ch[c], c); R->ch[c]->sz = R->ch[c]->sum = 1 ; r->ch[c]->d = Num;splay (R->ch[c]); return;} else R = R->ch[c];}} void ins2 (int num) {node *r = Root;bool C;while (1) {R->push (); if (num <= r->d) c = 0;else c = 1;if (R->ch[c] = = null) {R->ch[c] = NewNode (); R->setc (R->ch[c], c); Splay (R->ch[c]); gone + = Root->ch[0]->sUm ROOT->CH[1]->FA = null; ROOT = Root->ch[1];return;} else R = R->ch[c];}} int kth (int k) {node *r = Root;while (r! = null) {R->push (); if (R->ch[1]->sum >= k) R = R->ch[1];else if (r ->ch[1]->sum + R->sz >= k) return r->d;else K-= R->ch[1]->sum + R->sz, r = r->ch[0];} return 0;}} inline int getint () {int k = 0, fh = 1; char c = GetChar (); for (; c < ' 0 ' | | c > ' 9 '; c = GetChar ()) if (c = = '-') FH = -1;for (; c >= ' 0 ' && C <= ' 9 '; c = GetChar ()) K = k * + C-' 0 '; return k * FH; int main () {splay::build (); Read (n); read (M); int num;for (int i = 1; I <= n; ++i) {char c = getchar (); while (C < ' A ' | | C > ' Z ') c = getchar (); switch (c) {case ' I ': Read (num); if (num >= M) splay::ins (num); Break;case ' A ': Read (num); Root->d + = num; Root->lazy + = num; Root->push (); Break;case ' S ': Read (num); SPLAY::INS2 (num + M); Root->d-= num; Root->lazy-= num; Root->push (); Break;case ' F ': Read (num), if (num > Root->sum) putS ("-1"); else printf ("%d\n", splay::kth (num)); break;}} printf ("%d\n", Gone); return 0;}
"Bzoj 1503" "NOI 2004" Depressed Teller