PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000029. Tập hợp có thứ tự – Sáu thao tác (Ordered 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 hợp có thứ tự – Sáu thao tác (Ordered Set)
Ordered Set
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a set of distinct non-negative integers, initially listed in strictly increasing order. The set changes after updates, but no value can be present more than once.
Process queries, each containing two integers :
0 x: insert if absent.1 x: erase if present.2 x: output the -th smallest element, with ranks starting at , or-1if .3 x: count elements less than or equal to . Equal values count.4 x: output the largest element not exceeding , or-1if none exists.5 x: output the smallest element not below , or-1if none exists.
Queries are processed in order. Query operations inspect the current state without changing it.
Input
- Line 1: integers : initial set size and number of queries.
- Line 2: strictly increasing distinct integers ; this line is empty if .
- Next lines: exactly two integers , with query type in .
Output
For each type query, print one integer on a separate line: the requested value or count; use -1 for missing answers to types . Types produce no output.
Subtasks
Subtask 1 (20 points):
- .
- .
- if .
- for all queries.
- for each query.
- when .
- The initial set has distinct elements, without repetitions.
Subtask 2 (30 points):
- .
- .
- if .
- for all queries.
- for each query.
- when .
- The initial set has distinct elements, without repetitions.
Subtask 3 (50 points):
- .
- .
- if .
- for all queries.
- for each query.
- when .
- The initial set has distinct elements, without repetitions.
Examples
Input
3 12
10 20 30
3 19
3 20
4 19
4 20
5 21
2 2
0 0
2 1
0 0
1 20
3 20
2 4
Output
1
2
10
20
30
20
0
2
-1
Explanation
Initially .
3 19counts only , producing1.3 20includes and , producing2.4 19returns the greatest value at most :10.4 20includes equality, returning20.5 21returns the least value at least :30.2 2selects the second value of :20.0 0inserts : now .2 1returns the smallest element,0.- Another
0 0is ignored because is already present. 1 20removes , leaving .3 20counts and , producing2.2 4requests a fourth element of a three-element set, so output-1.