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

Input

  • 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.

Output

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'.

Example

Input
8
I -1
I -1
I 2
C 0
K 2
D -1
K 1
K 2

Output
1
2
2
invalid


Được gửi lên bởi:Jimmy
Ngày:2008-10-28
Thời gian chạy:1.5s-2s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:Chess

hide comments
2021-05-27 18:02:49
Tham khảo: https://vnspoj.github.io/problems/ORDERSET
2020-03-29 16:56:20
treap ez
2019-05-04 09:25:50
các bro cho e hỏi là dùng trie tìm số bé thứ k kiểu gì ạ :((
2018-09-24 03:27:08


Last edit: 2018-09-24 03:27:59
2017-08-21 10:17:33 Ðặng Minh Tiến
https://kienthuc24h.com/orderset-spoj-order-statistic-set/
2017-03-29 18:44:50 Nặc Danh
Dùng trie cũng AC ngay phát đầu
độ phức tạp bằng đúng 16*Q

Last edit: 2017-03-29 18:46:27
2016-12-17 04:48:41 THK6
BIT + Binary Search on BIT
2016-08-19 16:56:39
order_set zZ code < 40 dòng
2015-12-15 12:00:23 Hacking to the Gate
BIT & chặt nhị phân trên BIT
2015-02-13 02:08:57 *
IT tổng hoặc splay tree
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.