"Bzoj" "1503" "NOI2004" depressed cashier

Source: Internet
Author: User

Splay

Splay's template problem ... Proper sequence operation = = (there seems to be a time when you have not written this kind of pure data structure problem ...) )

1 /**************************************************************2 problem:15033 User:tunix4 language:c++5 result:accepted6 time:660 Ms7 memory:3644 KB8 ****************************************************************/9  Ten //Bzoj 1503 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AInlineintGetint () { at     intv=0, sign=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } - Const intn=1e5+ +, inf=~0u>>2; intypedefLong LongLL; - /******************tamplate*********************/ to intc[n][2],fa[n],v[n],add[n],size[n],n,m,root,cnt; + #defineL C[x][0] - #defineR C[x][1] the voidPUSH_UP (intx) { *size[x]=size[l]+size[r]+1; $ }Panax Notoginseng voidRotate (intx) { -     intY=fa[x],z=fa[y],l= c[y][1]==x, r=l^1; thec[z][c[z][1]==y]=x; +Fa[x]=z; Fa[y]=x; fa[c[x][r]]=y; AC[Y][L]=C[X][R]; c[x][r]=y; the push_up (y); + } - voidSplay (intXinty=0){ $      for(; fa[x]; Rotate (x)) { $y=Fa[x]; -         if(y!=root) -Rotate (c[y][1]==x^c[fa[y]][1]==y?x:y); the     } - push_up (x);Wuyiroot=x; the } - intFind (intW) { Wu     intx=root,y; -      while(x) { Abouty=x; $         if(v[x]>=w) x=L; -         Elsex=R; -     } -     returny; A } + voidInsert (intW) { the     if(!root) { -V[++cnt]=w; root=CNT; $fa[cnt]=0; size[cnt]=1; the         return; the     } the     intx=Find (w); thev[++cnt]=W; -Fa[cnt]=x; size[cnt]=1; in     if(V[X]&GT;=W) L=CNT; the     ElseR=CNT; the splay (CNT); About } the voidDel (intW) { the Insert (w); theroot=c[root][1]; +fa[root]=0; - } the intKthintXintk) {Bayi     if(k==size[l]+1)returnV[x]; the     Else if(K<=size[l])returnkth (l,k); the     Else returnKTH (r,k-size[l]-1); - } - intMain () { the #ifndef Online_judge theFreopen ("1503.in","R", stdin); theFreopen ("1503.out","W", stdout); the #endif -N=getint (); m=getint (); the     Charcmd[5];intx=0, ans=0, temp=0; theF (I,1, N) { thescanf"%s", CMD); x=getint ();94         if(cmd[0]=='I'){ the             if(x>=m) Insert (x-temp), ans++; the}Else if(cmd[0]=='A'){ thetemp+=x;98}Else if(cmd[0]=='S'){ Abouttemp-=x; -Del (M-temp);101}Else if(cmd[0]=='F'){102             if(X>size[root]) puts ("-1");103             Elseprintf"%d\n", KTH (root,size[root]-x+1)+temp);104         } the     }106printf"%d\n", ans-Size[root]);107     return 0;108}
View Code

1503: [NOI2004] Depressed teller time limit:5 Sec Memory limit:64 MB
submit:7176 solved:2525
[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

[Submit] [Status] [Discuss]

"Bzoj" "1503" "NOI2004" depressed cashier

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.