#FT0000041. Cây cân bằng thông thường (Normal Balanced Tree)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cây cân bằng thông thường (Normal Balanced Tree)
Normal Balanced Tree
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain an initially empty multiset of integers. A value can occur more than once; each occurrence counts separately in order statistics. Process operations:
1 x: insert one occurrence of .2 x: erase one occurrence of .3 x: output the rank of , defined as the number of elements strictly less than , plus one, even when is absent.4 k: output the value at rank in the sorted multiset, counting repeated values separately.5 x: output the strict predecessor of , i.e., the greatest value in strictly less than .6 x: output the strict successor of , i.e., the smallest value in strictly greater than .
For queries of types 4, 5, and 6, a valid answer is guaranteed. Query operations do not modify the multiset.
Input
- Line 1: integer , the operation count.
- Next lines: two integers per line; has the meaning defined by
op. Forop=4, is the rank .
Output
For each operation of type 3, 4, 5, or 6, print its integer answer on a separate line, preserving query order.
Subtasks
Subtask 1 (20 points):
- ; ; for types
1,2,3,5,6; for type4, ; every deletion targets an existing occurrence; answers to types4,5,6always exist.
Subtask 2 (30 points):
- ; ; for types
1,2,3,5,6; for type4, ; every deletion targets an existing occurrence; answers to types4,5,6always exist.
Subtask 3 (50 points):
- ; ; for types
1,2,3,5,6; for type4, ; every deletion targets an existing occurrence; answers to types4,5,6always exist.
Examples
Examples 1
Input
10
1 5
1 3
1 5
3 5
4 2
5 5
6 3
2 5
4 2
3 4
Output
2
5
3
5
5
2
Explanation
The first three operations produce sorted multiset . 3 5 returns ; 4 2 returns ; strict predecessor 5 5 returns ; strict successor 6 3 returns . Deleting one leaves , so 4 2 returns . Finally, 3 4 returns rank .
Examples 2
Input
6
1 -2
1 0
1 -2
3 0
4 2
5 0
Output
3
-2
-2
Explanation
The sorted multiset is . Two occurrences are less than , hence its rank is . The second smallest value is , and the greatest value strictly below is also .
The two insertions of remain as two separate copies. Operation 4 2 only queries the second element of ; it does not remove it. The multiset is therefore unchanged before 5 0, whose predecessor of is .