"NOI2004" Depressed Teller

Source: Internet
Author: User
Tags min
"NOI2004" depressed teller "Title 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. Well, it's not very difficult. "Input" The first line has two non-negative integers n and min. n indicates how many commands are below and min represents the lower bound of wages.
Next n rows, each line represents a command. The command can be one of the following four:
I Command I_k
Create a new payroll file with an initial wage of K. If an employee's initial wage falls below the lower salary, he will leave the company immediately.
A Command A_k
Add the wages of each employee to K
S Command S_k
Deduct the wages of each employee K
F Command F_k
Enquire about K-pay
_ (underscore) denotes a space, the I command, the A command, the K in the S command is a nonnegative integer, and the k in the F command is a positive integer.
At the beginning, it can be assumed that there is not a single employee in the company.
"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.
"Input Sample" 9 10
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2
"output Example" 10
20
-1
2
"Data range" the number of bars in the I command does not exceed 100000
A command and S command have no more than 100 total number of bars
The number of bars in the F command does not exceed 100000
The adjustment amount of each salary adjustment does not exceed 1000
The salary of the new employee does not exceed 100000
" The Puzzle" This problem treap can be done, for I command directly by size insertion, f command is also the basic kth operation. The trouble is the A and S command, the direct modification of the wages of everyone is too high, so we use a variable h record salary changes, encountered a command plus K, encountered S command minus K. When inserting, determine if k is greater than or equal to the minimum value T, if inserting k-h is satisfied to eliminate the effect of the previous modification. A command does not cause employees to leave, s commands need extra consideration, as long as the down-looking process to delete the root and left subtree. Notice that the F command is found to add h, and nothing else. "Code" did not compare with splay practice, it seems that line tree, tree array can also be too, but treap time has been excellent. "NOI2004" depressed Teller # code
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.