#P3380. 【模板】树套树
【模板】树套树
Description
You need to implement a data structure (you may refer to the problem title) to maintain a sequence, supporting the following operations:
- Query the rank of within a range.
- Query the value whose rank is within a range.
- Modify the value at a certain position.
- Query the predecessor of within a range (the predecessor is defined as the largest number that is strictly less than , and if it does not exist, output
-2147483647). - Query the successor of within a range (the successor is defined as the smallest number that is strictly greater than , and if it does not exist, output
2147483647).
For a set of elements, the rank of a number is defined as the count of elements strictly smaller than it plus one, and the number with rank is defined as “the element that would be at position after sorting the elements in ascending order.”
Input Format
The first line contains two integers , denoting a sequence of length and operations.
The second line contains integers, representing the sequence.
The next lines each contain an operation, where denotes the operation id.
If , it is operation 1. Then there are three integers , meaning: query the rank of in the range .
If , it is operation 2. Then there are three integers , meaning: query the number whose rank is in the range .
If , it is operation 3. Then there are two integers , meaning: modify the value at position to .
If , it is operation 4. Then there are three integers , meaning: query the predecessor of in the range .
If , it is operation 5. Then there are three integers , meaning: query the successor of in the range .
Output Format
For operations , output one line for each query, representing the result.
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
2
4
3
4
9
Hint
Constraints: , and the values in the sequence are always in at any time.
Problem source: bzoj3196 / Tyvj1730, with thanks.
This testdata is original to Luogu. Special reminder: this testdata does not guarantee that the answers for operations 4 and 5 always exist, so please be sure to handle the nonexistence cases.
Translated by ChatGPT 5
京公网安备 11011102002149号