Kiki's k-Number
Time Limit: 4000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2598 accepted submission (s): 1199
Problem descriptionfor the k-th number, we all shoshould be very familiar with it. of course, to Kiki it is also simple. now Kiki meets a very similar problem, Kiki wants to design a container, the container is to support the three operations.
Push: Push a given element e to container
Pop: Pop element of a given E from Container
Query: Given two elements A and K, query the kth larger number which greater than a in iner;
Although kiki is very intelligent, she can not think of how to do it, can you help her to solve this problem?
Inputinput some groups of test data, each test data the first number is an integer m (1 <= m <100000), means that the number of operation to do. the next M lines, each line will be an integer p at the beginning, P which has three values:
If P is 0, then there will be an integer e (0 <e <100000), means press Element E into container.
If P is 1, then there will be an integer e (0 <e <100000), indicated that Delete the Element E from the container
If P is 2, then there will be two integers A and K (0 <A <100000, 0 <k <10000), means the inquiries, the element is greater than, and the k-th larger number.
Outputfor Each deletion, if you want to delete the element which does not exist, the output "No elment! ". For each query, output the suitable answers in line. If the number does not exist, the output" not find! ".
Sample Input
50 51 20 62 3 22 8 170 20 20 42 1 12 1 22 1 32 1 4
Sample output
No Elment!6Not Find!224Not Find!
Source
0 indicates adding a node
1 indicates deleting a node
2. Find the number k greater than B.
# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <algorithm> # include <cmath> # define Init (a) memset (, 0, sizeof (A) using namespace STD; # define Max int_max # define min int_min # define ll _ int64 # define lson l, m, RT <1 # define rson m + 1, R, RT <1 | 1 const int maxn = 300010; const int maxm = 100010; using namespace STD; int C [maxn]; int hash [maxm]; int lowbit (int x) {re Turn X & (-x);} void add (int x, int W) {While (x <= maxn) {C [x] + = W; X + = lowbit (x) ;}} int sum (int I) {int S = 0; while (I> 0) {S + = C [I]; I = I-lowbit (I);} return s;} void B _search (int B, int K) {int TEM = sum (B); int low = B; int high = maxm; int mid; while (low <= high) {mid = (low + high)/2; int ST = sum (MID ); if (hash [Mid]> 0 & St-Hash [Mid]-tem <K & St-tem> = K) // hash reduction is performed because multiple identical elements may exist. {break;} If (St-tem <K) {LOW = Mid + 1;} else high = mid-1;} printf ("% d \ n", mid);} bool query (int B, int K) {If (sum (maxn)-sum (B) <k) return 0; B _search (B, k); return 1 ;}int main () {int N,, b, K; while (scanf ("% d", & N )! = EOF) {Init (c); Init (hash); For (INT I = 0; I <n; I ++) {scanf ("% d ", & A); if (a = 0) {scanf ("% d", & B); add (B, 1); hash [B] ++ ;} else if (a = 1) {scanf ("% d", & B); If (hash [B]> 0) {Add (B,-1 ); hash [B] --;} else puts ("No elment! ");} Else if (a = 2) {scanf (" % d ", & B, & K); bool TEP = query (B, k ); if (! TEP) puts ("not find! ") ;}}Return 0 ;}