PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000034. Tập số có truy vấn thứ hạng (ORDERSET - Order statistic set)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tập số có truy vấn thứ hạng (ORDERSET - Order statistic set)
ORDERSET - Order statistic set
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a dynamic set of distinct integers, initially empty. I x inserts if absent, D x removes if present, C x counts elements strictly smaller than , and K kreturns the $k$-th smallest element. If there is no such element, printinvalid` exactly.
Input
The first line contains . Each of the next lines contains I, D, C, or K followed by its integer argument.
Output
For each C or K operation, print its answer. Print invalid for an invalid K request.
Subtasks
- Subtask 1 (20 points): ; for
I,D,C: ; forK: . - Subtask 2 (30 points): ; for
I,D,C: ; forK: . - Subtask 3 (50 points): ; for
I,D,C: ; forK: .
Examples
Input
8
I -1
I -1
I 2
C 0
K 2
D -1
K 1
K 2
Output
1
2
2
invalid
Explanation
Inserting -1 twice keeps one copy. After removing -1, only 2 remains, so K 2 is invalid.