Topic Description Description
Oier Company is a large-scale specialized software company, has tens of thousands of employees. As a cashier, one of my tasks is to count the salaries of each employee. It would have been a good job, but it was frustrating that our bosses were fickle and often adjusted their 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 may be their wages deducted a same amount. I really don't know what else he's doing except for the pay raise.
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 under the lower wages, he will immediately angrily leave the company, and never come back. The lower salary of each employee is uniformly stipulated. Every time a person leaves the company, I will delete his payroll file from the computer, again, whenever the company hires a new employee, I have to create a new payroll file for him.
The boss often come to my side to ask about the salary, he does not ask a specific employee's salary, but asked how many employees now pay K how much wages. At this point, I had to do a lengthy sort of tens of thousands of employees and tell him the answer.
Well, now you've learned a lot about my job. As you guessed, I would like to ask you to compile a payroll statistics program. It's not very difficult, is it? Input description Input Description
The first row has two nonnegative integers n and Min. n indicates how many commands are below, min indicates the lower salary.
The next n lines, each line represents a command. The command can be one of the following four types:
Name |
Format |
Role |
I command |
I_k |
Create a new payroll file with the initial salary of K. If an employee's initial salary is below the lower wage, he will leave the company immediately. |
a command |
A_k |
Add k to each employee's salary |
s command |
S_k |
Deduct every employee's salary from K |
F command |
F_k |
Inquire about the wages of K-much |
_ (underline) denotes a space, the i command, a command, the K in the S command is a nonnegative integer, and K in the F command is a positive integer.
At the beginning, you can assume that there is not a single employee in the company. Output Description Description
The number of rows in the output file is the number of bars in the F command plus one.
For each f command, your program outputs a row, contains only one integer, the number of salaries for employees who are currently paid a K-number, 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 have left the company. Sample Input For example
9 10
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2 Sample Output sample
10
20
-1
2 range and hint data Size & Hint
Agreed
L command the number of bars not exceeding 100000
L a command and the total number of S commands not exceeding 100
L command the number of bars not exceeding 100000
L adjustment for each wage adjustment does not exceed 1000
L The salary of the new employee does not exceed 100000
The state of violence has changed to a 2333.
But on the bzoj, I don't know why re Qaq
For help, Qaq.
But it must be a detail error = = The program ontology should be OK.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <
algorithm> #define LCHILD rt<<1,l,m #define RCHILD rt<<1|1,m+1,r using namespace std; struct SBT {int left,right,size,data;}
TREE[200001];
int sum;
int N,minn;
string ch;
int now;
int key;
int root,top;
void Left_rot (int &x) {int y=tree[x].right;
Tree[x].right=tree[y].left;
Tree[y].left=x;
Tree[y].size=tree[x].size;
tree[x].size=tree[tree[x].left].size+tree[tree[x].right].size+1;
X=y;
} void Right_rot (int &x) {int y=tree[x].left;
Tree[x].left=tree[y].right;
Tree[y].right=x;
Tree[y].size=tree[x].size;
tree[x].size=tree[tree[x].left].size+tree[tree[x].right].size+1;
X=y; } void maintain (int &x,bool flag) {if (!flag) {if (tree[tree[tree[x].left].left].size>tree[tree[x].right].siz
e) Right_rot (x);
else if (tree[tree[tree[x].left].right].size>tree[tree[x].right].size) Left_rot (Tree[x].left), Right_rot (x); ELSE retUrn
else {if (tree[tree[tree[x].right].right].size>tree[tree[x].left].size) Left_rot (x);
else if (tree[tree[tree[x].right].left].size>tree[tree[x].left].size) Right_rot (tree[x].right), Left_rot (x);
else return;
} maintain (tree[x].left,0);
Maintain (tree[x].right,1);
Maintain (x,1);
Maintain (x,0);
} void Insert (int &x,int data) {if (x==0) {x=++top;
tree[x].left=tree[x].right=0;
tree[x].size=1;
Tree[x].data=data;
else {tree[x].size++;
if (data<tree[x].data) insert (tree[x].left,data);
else insert (tree[x].right,data);
Maintain (x,data>=tree[x].data);
int remove (int &x,int data) {tree[x].size--;
if (tree[x].data>data) remove (tree[x].left,data);
else if (tree[x].data<data) remove (tree[x].right,data);
else {if (tree[x].left!=0&&tree[x].right==0) {int ret=x;
X=tree[x].left;
return ret;
else if (tree[x].left==0&&tree[x].right!=0) {int ret=x; x=Tree[x].right;
return ret;
else if (tree[x].left==0&&tree[x].right==0) {int ret=x;
x=0;
return ret;
else if (tree[x].left!=0&&tree[x].right!=0) {int ret=tree[x].right;
while (Tree[ret].left) Ret=tree[ret].left;
Tree[x].data=tree[ret].data;
Remove (Tree[x].right,tree[ret].data);
an int select (int &x,int k) {int r=tree[tree[x].left].size+1;
if (r==k) return tree[x].data;
else if (r<k) return select (Tree[x].right,k-r);
else if (r>k) return select (Tree[x].left,k);
int getmin () {int x;
for (X=root;tree[x].left;x=tree[x].left);
return tree[x].data;
int main () {freopen ("cashier.in", "R", stdin);
Freopen ("Cashier.out", "w", stdout);
scanf ("%d%d", &n,&minn);
for (int i=1;i<=n;i++) {cin>>ch;
scanf ("%d", &key);
if (now) while (Getmin () <minn) {Remove (Root,getmin ());
sum++;
now--;
} if (ch== "I") {if (Key>=minn)Insert (Root,key), now++;
else if (ch== "A") for (int j=1;j<=top;j++) Tree[j].data+=key;
else if (ch== "S") for (int j=1;j<=top;j++) Tree[j].data-=key;
else if (ch== "F") {if (Key>now) {printf (" -1\n");
Continue
else printf ("%d\n", select (root,now-key+1));
}} cout<<sum; }