_bzoj1503 [NOI2004] Depressed Teller "Splay"

Source: Internet
Author: User

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

Employees who leave because the initial wage does not meet the lower limit are not counted in the number of departures ... The pit Daddy ...

Then it is time to write kth, forget to consider the value of the current node may appear more than once ...

#include <cstdio>const int maxn = 100005;int N, min_salary, Zengl, root, cnt = 1, T1, Leave;int ch[maxn][2], FA[MAXN ], SIZ[MAXN], KEY[MAXN], Tm[maxn];char opr;inline void pushup (int x) {siz[x] = Siz[ch[x][0]] + siz[ch[x][1]] + tm[x];} inline void rotate (int x) {int y = fa[x];if (y = = Ch[fa[y]][0]) {ch[fa[y]][0] = x;} else {ch[fa[y]][1] = x;} Fa[x] = Fa[y];int dir = x = = Ch[y][1];ch[y][dir] = ch[x][dir ^ 1];fa[ch[x][dir ^ 1]] = y;ch[x][dir ^ 1] = Y;fa[y] = X;push Up (y);p ushup (x);} inline void splay (int x) {int P;char Flag1, flag2;while (Fa[x]) {p = fa[x];if (!fa[p]) {rotate (x);} else {Flag1 = p = = Ch[fa[p]][1];flag2 = x = = Ch[p][1];if (flag1 ^ flag2) {rotate (x);} else {rotate (p);} Rotate (x);}} root = x;} inline int Houji (int val) {int rt = 0, x = Root;while (x && val! = key[x] + Zengl) {if (Val < key[x] + Zengl) { RT = X;x = Ch[x][0];} else {x = ch[x][1];}} return x? X:rt;} BOOL ist (int x, int val, int p, int dir) {if (!x) {++cnt;key[cnt] = val-zengl;tm[cnt] = 1;siz[cnt] = 1;FA[CNT] = P;ch[p][dir] = Cnt;return true;} if (val = = Key[x] + Zengl) {++tm[x];++siz[x];return false;} int d = val > key[x] + zengl;bool RT = IST (Ch[x][d], Val, X, D);p ushup (x); return RT;} inline int kth (int k) {int x = Root;while (k > siz[ch[x][1]] + tm[x] | | k <= SIZ[CH[X][1]]) {if (K > Siz[ch[x][1] ] + tm[x]) {k-= siz[ch[x][1]] + tm[x];x = ch[x][0];} else {x = ch[x][1];}} return key[x] + Zengl;} int main (void) {//freopen ("In.txt", "R", stdin), scanf ("%d%d", &n, &min_salary); key[1] = 2000000000;siz[1] = 1;tm [1] = 1;root = 1;while (n--) {while ((OPR = GetChar ()) < ' A '), scanf ("%d", &t1), if (OPR = = ' I ') {if (T1 >= Min_sa Lary && ist (root, T1, 0, 0)) {splay (CNT);}} else if (OPR = = ' a ' | | opr = = ' S ') {Zengl + = (OPR = = ' A '? T1:-t1); Splay (Houji (min_salary)); leave + = Siz[ch[root][0]];ch[r Oot][0] = 0;pushup (root);} else {printf ("%d\n", T1 > Siz[root]-1 -1:kth (t1 + 1));}} printf ("%d\n", leave); return 0;}

  

_bzoj1503 [NOI2004] Depressed Teller "Splay"

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.