#FT0000228. Cây lồng cây – thống kê thứ tự trên đoạn (Tree of Trees)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cây lồng cây – thống kê thứ tự trên đoạn (Tree of Trees)
Tree of Trees
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of nonnegative integers, indexed from . Elements may be modified as operations are performed.
Support the following five operation types, processing them in input order:
1 l r k: Output the rank of value within , defined as the number of elements strictly smaller than in that interval plus . The value need not occur in the interval.2 l r k: Output the -th smallest value in , with duplicate values counted as separate entries.3 pos k: Set .4 l r k: Output the largest value strictly less than in (the predecessor). If it does not exist, output exactly-2147483647.5 l r k: Output the smallest value strictly greater than in (the successor). If it does not exist, output exactly2147483647.
Each interval is inclusive at both ends. Distinguish the rank of a value (type 1) from the value of a given rank (type 2).
Input
- The first line contains two integers , the array length and operation count.
- The second line contains exactly integers in index order.
- Each of the next lines starts with
optfrom . - If
optis1,2,4or5, it is followed by three integersl r k. - If
optis3, it is followed by two integerspos k.
Output
For each operation of type 1, 2, 4 or 5, output one integer on its own line, in operation order. Use the exact sentinel values -2147483647 and 2147483647 for missing predecessors and successors respectively. A type-3 assignment prints nothing.
Subtasks
- Subtask 1 (20 points): ; ; for every and after every assignment; for types
1,2,4,5: ; for types1,4,5: ; for type2: ; for type3: and . - Subtask 2 (30 points): ; ; for every and after every assignment; for types
1,2,4,5: ; for types1,4,5: ; for type2: ; for type3: and . - Subtask 3 (50 points): ; ; for every and after every assignment; for types
1,2,4,5: ; for types1,4,5: ; for type2: ; for type3: and .
Examples
Input
9 6
4 2 2 1 9 4 0 1 1
2 1 4 3
3 4 10
2 1 4 3
1 2 5 9
4 3 9 5
5 2 8 5
Output
2
4
3
4
9
Explanation
The initial array is .
2 1 4 3: Sorting gives ; the third value is .3 4 10: Set the fourth element to , resulting in .2 1 4 3: Sorting the new prefix gives , with third value .1 2 5 9: In , exactly two elements are strictly less than , so its rank is .4 3 9 5: In the interval , the greatest value below is .5 2 8 5: In the interval , the smallest value above is .
The five answers are therefore 2, 4, 3, 4, 9.
Example 2
Input
3 4
1 2 3
4 1 3 1
5 1 3 3
1 1 3 2
2 1 3 2
Output
-2147483647
2147483647
2
2
Explanation
In , no element is smaller than , so type 4 must print -2147483647. No element is larger than , so type 5 prints 2147483647. The rank of is because only one element is strictly smaller; the second-smallest value is also .