[NOI2004] [BZOJ1503] Depressed Teller

Source: Internet
Author: User

1503: [NOI2004] Depressed teller time limit:5 Sec Memory limit:64 MB
submit:7749 solved:2725
[Submit] [Status] [Discuss] 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

Source

Splay

Treap 800ms ... Naked question
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespacestd;Charc[1];intN,mn,x,cnt,delta,root,leave;intsize[100005],num[100005],l[100005],r[100005],rnd[100005];voidUpdata (intx) {Size[x]=size[l[x]]+size[r[x]]+1;}voidRturn (int&k) {    intT=l[k];l[k]=r[t];r[t]=k;updata (k); Updata (t); k=t;}voidLturn (int&k) {    intT=r[k];r[k]=l[t];l[t]=k;updata (k); Updata (t); k=t;}voidInsertint&k,intx) {    if(!k) {k=++CNT; NUM[K]=x; RND[K]=rand (); SIZE[K]=1; return; } Size[k]++; if(x<Num[k])        {Insert (L[K],X); if(rnd[l[k]]<Rnd[k]) Rturn (k); }    Else{Insert (r[k],x); if(rnd[r[k]]<Rnd[k]) Lturn (k); }}intDelint&k,intx) {    intT; if(!k)return 0; if(num[k]<x) {T=size[l[k]]+1; K=R[k]; returnt+del (K,X); }    Else{T=del (L[K],X); SIZE[K]-=T; returnT; }}intFindintKintx) {    if(size[l[k]]+1==X)returnnum[k]+Delta; if(size[l[k]]+1&GT;X)returnfind (L[K],X); if(size[l[k]]+1&LT;X)returnFind (r[k],x-size[l[k]]-1);}intMain () {scanf ("%d%d",&n,&mn);  while(n--) {scanf ("%s%d",c,&x); if(c[0]=='I')             if(X&GT;=MN) Insert (root,x-Delta); if(c[0]=='A') delta+=x; if(c[0]=='S') {Delta-=x; Leave+=del (root,mn-Delta); }        if(c[0]=='F')            if(X>size[root]) printf ("-1\n"); Elseprintf"%d\n", Find (root,size[root]-x+1)); } printf ("%d", leave); return 0;}

[NOI2004] [BZOJ1503] Depressed Teller

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.