#P6136. 【模板】普通平衡树(数据加强版)
【模板】普通平衡树(数据加强版)
Background
This problem is the enhanced testdata version of P3369. It expands the constraints and adds forced online.
The input and output of this problem are slightly different from the original one, but the operations that need to be supported are the same.
Problem Description
You need to dynamically maintain a multiset , and provide the following operations:
- Insert a number into .
- Delete a number from (if there are multiple identical numbers, delete only one).
- Query how many numbers in are less than , and then add to the result.
- Query the number whose rank is the -th when is sorted in increasing order.
- Query the predecessor of in (the predecessor is defined as the largest number less than ).
- Query the successor of in (the successor is defined as the smallest number greater than ).
This problem is forced online. All operations are guaranteed to be valid (for operation , there is guaranteed to be at least one ; for operations , an answer is guaranteed to exist).
Input Format
The first line contains two positive integers , representing the number of initial numbers and the number of operations.
The second line contains integers , representing the initial numbers.
Next there are lines, each containing two integers and . indicates the operation index (), and indicates the encrypted operand.
Let denote the answer of the most recent operation among . Then in each operation, the real is obtained by XORing with . Initially, .
Output Format
Output one line with one integer, representing the XOR sum of the answers of all operations .
6 7
1 1 4 5 1 4
2 1
1 9
4 1
5 8
3 13
6 7
1 4
6
Hint
Sample Explanation
Before encryption, the sample is:
6 7
1 1 4 5 1 4
2 1
1 9
4 1
5 9
3 8
6 1
1 0
::::info[Output of each operation] Before the first operation, . After it, .
After the second operation, .
The third operation queries the -st smallest number in , and the answer is .
The fourth operation queries the predecessor of in , and the answer is .
The fifth operation queries how many numbers in are less than , and then adds to the result. The answer is .
The sixth operation queries the successor of in , and the answer is .
After the seventh operation, .
The output is . ::::
Limits and Notes
For of the testdata, , , .
The input size of this problem is large. Please use a fast input method.
: Added new sets of hack testdata.
Translated by ChatGPT 5