ORDERSET - Order statistic set
In this problem, you have to maintain a dynamic set of numbers which support the two fundamental operations
- INSERT(S,x): if x is not in S, insert x into S
- DELETE(S,x): if x is in S, delete x from S
and the two type of queries
- K-TH(S) : return the k-th smallest element of S
- COUNT(S,x): return the number of elements of S smaller than x
- Line 1: Q (1 ≤ Q ≤ 200000), the number of operations
- In the next Q lines, the first token of each line is a character I, D, K or C meaning that the corresponding operation is INSERT, DELETE, K-TH or COUNT, respectively, following by a whitespace and an integer which is the parameter for that operation.
If the parameter is a value x, it is guaranteed that 0 ≤ |x| ≤ 109. If the parameter is an index k, it is guaranteed that 1 ≤ k ≤ 109.
For each query, print the corresponding result in a single line. In particular, for the queries K-TH, if k is larger than the number of elements in S, print the word 'invalid'.
Input 8 I -1 I -1 I 2 C 0 K 2 D -1 K 1 K 2 Output 1 2 2 invalid
Any Java programmer here who got it accepted ? I am hearing only c++programs. In Java, even with Compression + BIT + Binary search + Fast I/O, I am getting TLE after test case #6.
Implemented with BIT. But constantly getting WA after test case #5. Any hint ?
map with bit->0.56sec
BIT - 0.35s
TLE with std::map, AC with std::unordered_map
Direct implementation of policy based data structures in C++
Just loved it......Learned a lot !!
Amazing problem...learnt a lot...time to play cs
The four magic lines of code... :)
Must do question for beginners in BIT