[BZOJ1503] [NOI2004] Depressed Teller (treap)

Source: Internet
Author: User

Description

Oier Company is a large specialized software company, with tens of thousands of employees. As a teller, one of my tasks is to count the wages of each employee. It was supposed to be a good job, but the depressing part is that our bosses are fickle and often adjust their employees ' salaries. If he is in a good mood, he may add the same amount to each employee's salary. Conversely, if the mood is not good, it is possible to deduct their wages by a similar amount. I really don't know what else he's going to do in addition to the salary adjustment. The frequent adjustment of wages is very annoying to employees, especially when the collective deduction of wages, once an employee found that his salary is lower than the contract stipulated wages, he would immediately angrily leave the company, and will never come back. The lower bound of wages for each employee is uniformly defined. Whenever a person leaves the company, I have to delete his payroll file from the computer, as well, whenever the company hires a new employee, I have to create a new payroll file for him. The boss often came to my side to inquire about the salary, he did not ask the specific employee's salary, but asked how much the salary of the employees of the K-m pay. At this point, I had to make a lengthy sort of tens of thousands of employees and tell him the answer. Well, now you've learned a lot about my work. As you guessed, I would like to ask you to compile a payroll statistics program. It's not very difficult, is it?

Input

Output

The number of rows in the output file is the number of bars of the F command plus one. For each f command, your program will output a line that contains only an integer, the number of wages for employees with a current salary of more than K, and if K is greater than the current number of employees, output-1. The last line of the output file contains an integer that is the total number of employees who leave the company.

Sample Input9 10
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2
Sample Output10
20
-1
2
HINT

The number of bars of the I command does not exceed the number of bars of the 100000 a command and the S command, no more than 100000 of the bar of the command, no more than 1000 of the adjustment amount per salary adjustment does not exceed 100000 of the new employee's salary

SourceSolution

Because every time the increase and decrease in wages is for all staff, so we can make a $lazy$ mark on the whole, indicating the change of wages

$treap $ is recorded in real wages for everyone $x$ minus $lazy$ value

So, for a new person, the relative value of his salary is the value of the initial wage $k$ minus $lazy$.

Query operation because to check the $k$ large, for convenience, can from large to small maintenance $treap$, and then there is no difficulty

There is a pole pit point: If a person's initial wage is lower than $min$, this person does not count to leave the company!!! The answer does not count this person!!!

1#include <bits/stdc++.h>2 using namespacestd;3 structtreap4 {5     intL, R, Siz, PRI, Key, Val;6}a[100005];7 intans, ptot;8 9 voidPUSH_UP (intk)Ten { OneA[k].siz = a[a[k].l].siz + A[a[k].r].siz +A[k].val; A } -  - voidLturn (int&k) the { -     intTMP =A[K].R; -A[K].R = a[tmp].l, A[TMP].L =K; -A[tmp].siz = A[k].siz, push_up (k), k =tmp; + } -  + voidRturn (int&k) A { at     intTMP =A[K].L; -A[K].L = A[TMP].R, A[TMP].R =K; -A[tmp].siz = A[k].siz, push_up (k), k =tmp; - } -  - voidInsertint&k,intx) in { -     if(!k) to     { +K = ++ptot, A[k].siz = A[k].val =1; -A[k].key = x, A[k].pri =rand (); the         return; *     } $++A[k].siz;Panax Notoginseng     if(x = = A[k].key) + +A[k].val; -     Else if(X >A[k].key) the     { + Insert (A[K].L, x); A         if(A[a[k].l].pri >A[k].pri) Rturn (k); the     } +     Else -     { $ Insert (A[K].R, x); $         if(A[a[k].r].pri >A[k].pri) Lturn (k); -     } - } the  - voidDelint&k,intx)Wuyi { the     if(!k)return; -     if(x <=a[k].key) del (A[K].R, X), push_up (k); Wu     Else -     { AboutAns + = A[a[k].r].siz +A[k].val; $A[K].R =0, k =A[K].L; - del (k, X), push_up (k); -     } - } A  + intFind_kth (intKintx) the { -     if(!k)return-1; $     if(x <= A[a[k].l].siz)returnfind_kth (A[K].L, x); the     if(x <= a[a[k].l].siz + a[k].val)returnK; the     returnFind_kth (A[K].R, X-a[a[k].l].siz-a[k].val); the } the  - intMain () in { the     intN, M, K, root =0, lazy =0; the     Charop[5]; Aboutscanf"%d%d", &n, &m); the Srand (n); the      while(n--) the     { +scanf"%s%d", OP, &k); -         if(op[0] =='I') the         {Bayi             if(K < m)Continue; theInsert (root, K-lazy); the         } -         if(op[0] =='A') Lazy + =K; -         if(op[0] =='S') the         { theLazy-=K; theDel (Root, M-lazy); the         } -         if(op[0] =='F') the         { theK =find_kth (root, k); theprintf"%d\n", ~k? A[k].key + Lazy:-1);94         } the     } theprintf"%d\n", ans); the     return 0;98}
View Code

[BZOJ1503] [NOI2004] Depressed Teller (treap)

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.