TYVJ P1851 [NOI2004] depressed Teller (treap)

Source: Internet
Author: User
Tags min printf

Topic links

Time: 1000ms/Space: 131072kib/java class Name: MainDescriptionOier 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 FormatThe 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:
Name format effect
I command I_k to 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 The wages of each employee plus K
S command S_k to deduct the wages of each employee K
F Order F_k to inquire about the 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 FormatThe 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.
Test Sample 1 input9 10
I 60
I 70
S 50
F 2
I 30
S 15
A 5
F 1
F 2Output10
20
-1
2NotesThe 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 is not more than 100000
NOI2004


Puzzle: Simple Treap

The code is as follows:

#include <stdio.h> #include <iostream> #include <algorithm> #include <map> #include <
string.h> #define NN 11000 #define MOD 100003 typedef long LL;
typedef unsigned long long LLU;
using namespace Std;
    struct Node {node* Lson;
    node* Rson;
    int Val;
    int key;
    int num;
int treenumber;
}*root;
int n,m;
int ans; int Numofnode (node *id) {return id==null?0:id->treenumber;} void Update (node *id) {if (id==null) Retu
    RN;
Id->treenumber=id->num+numofnode (Id->lson) +numofnode (Id->rson);
    } void Right_rotate (node* &id) {node *tem=id->lson;
    id->lson=tem->rson;
    tem->rson=id;
    Update (ID);
    Update (TEM);
Id=tem;
    } void Left_rotate (node *&id) {node *tem=id->rson;
    id->rson=tem->lson;
    tem->lson=id;
    Update (ID);
    Update (TEM);
Id=tem;
        } void Insert (node* &id,int val) {if (id==null) {id=new node; Id->lson=id->rsOn=null;
        id->val=val;
        Id->key=rand ();
        id->num=1;
        id->treenumber=1;
    return;
        } if (Id->val==val) {id->num++;
        id->treenumber++;
    return;
        } if (Id->val>val) {Insert (id->lson,val);
        Update (ID);
        if (Id->lson->key<id->key) {right_rotate (ID);
        }} else {Insert (id->rson,val);
        Update (ID);
        if (Id->rson->key<id->key) {left_rotate (ID);
    }}} void Change (node *id,int val) {if (id==null) return;
    Change (Id->lson,val);
    Change (Id->rson,val);
    id->val+=val;
        if (id->val<m) {ans+=id->num;
    id->num=0;

} update (ID);
    } int Ask (node *id,int k) {if (Numofnode (ID) <k) return-1;
    if (Numofnode (Id->rson) >=k) {return ask (id->rson,k);
 }   else if (Numofnode (Id->rson) +id->num>=k) return id->val;
Return Ask (Id->lson,k-numofnode (Id->rson)-id->num);
    } int main () {char s[10];
    int D;
        while (scanf ("%d%d", &n,&m)!=eof) {root=null;
        ans=0;
            while (n--) {scanf ("%s%d", s,&d);
                if (s[0]== ' I ') {if (d<m) continue;
            Insert (ROOT,D);
            } else if (s[0]== ' A ') {change (root,d);
            } else if (s[0]== ' s ') {change (root,-d);
        } else printf ("%d\n", Ask (Root,d));
    } printf ("%d\n", ans);
} return 0;
 }


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.