PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000031. Truy vấn dãy số theo ngưỡng (Sequence Query)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn dãy số theo ngưỡng (Sequence Query)
Sequence Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Initially, sequence is empty. You may append positive integers to it; duplicate values are allowed, and every occurrence contributes separately to order-statistic queries.
Process commands of three types:
1 x: add an element of value to .2 x k: among existing elements at most , report the -th largest value, counting duplicates. Print-1if fewer than such elements exist.3 x k: among existing elements at least , report the -th smallest value, counting duplicates. Print-1if there are not enough such elements.
All commands are executed in input order. Types do not change the sequence.
Input
- Line 1: integer .
- Next lines: an operation in one of the formats
1 x,2 x k, or3 x k; for the last two formats, is the rank within the values satisfying threshold .
Output
For every type or query, print one integer on a separate line: the requested value, or -1 if too few elements exist, in query order. Type produces no output.
Subtasks
Subtask 1 (20 points):
- .
- in all commands.
- is the command type.
- in every type or command.
- The sequence is initially empty and permits repeated values.
Subtask 2 (30 points):
- .
- in all commands.
- is the command type.
- in every type or command.
- The sequence is initially empty and permits repeated values.
Subtask 3 (50 points):
- .
- in all commands.
- is the command type.
- in every type or command.
- The sequence is initially empty and permits repeated values.
Examples
Input
11
1 20
1 10
1 30
1 20
3 15 1
3 15 2
3 15 3
3 15 4
2 100 5
1 1
2 100 5
Output
20
20
30
-1
-1
1
Explanation
After four insertions, the sequence contains , or in sorted order.
- The three queries
3 15 1,3 15 2,3 15 3consider only values at least , namely , producing20,20, and30. The two copies of count separately. 3 15 4requests a fourth element from a three-element group, producing-1.2 100 5includes all four values but asks for rank five, so print-1.1 1adds . The five values in descending order are now , and2 100 5returns1.