#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 MM, and provide the following operations:

  1. Insert a number xx into MM.
  2. Delete a number xx from MM (if there are multiple identical numbers, delete only one).
  3. Query how many numbers in MM are less than xx, and then add 11 to the result.
  4. Query the number whose rank is the xx-th when MM is sorted in increasing order.
  5. Query the predecessor of xx in MM (the predecessor is defined as the largest number less than xx).
  6. Query the successor of xx in MM (the successor is defined as the smallest number greater than xx).

This problem is forced online. All operations are guaranteed to be valid (for operation 22, there is guaranteed to be at least one xx; for operations 4,5,64,5,6, an answer is guaranteed to exist).

Input Format

The first line contains two positive integers n,mn,m, representing the number of initial numbers and the number of operations.

The second line contains nn integers a1,a2,a3,,ana_1,a_2,a_3,\ldots,a_n, representing the initial numbers.

Next there are mm lines, each containing two integers opt\text{opt} and xx'. opt\text{opt} indicates the operation index (1opt6 1 \leq \text{opt} \leq 6 ), and xx' indicates the encrypted operand.

Let last\text{last} denote the answer of the most recent operation among 3,4,5,63,4,5,6. Then in each operation, the real xx is obtained by XORing xx' with last\text{last}. Initially, last=0\text{last}=0.

Output Format

Output one line with one integer, representing the XOR sum of the answers of all operations 3,4,5,63,4,5,6.

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, M={1,1,1,4,4,5}M=\{1,1,1,4,4,5\}. After it, M={1,1,4,4,5}M=\{1,1,4,4,5\}.

After the second operation, M={1,1,4,4,5,9}M=\{1,1,4,4,5,9\}.

The third operation queries the 11-st smallest number in MM, and the answer is 11.

The fourth operation queries the predecessor of 99 in MM, and the answer is 55.

The fifth operation queries how many numbers in MM are less than 88, and then adds 11 to the result. The answer is 66.

The sixth operation queries the successor of 11 in MM, and the answer is 44.

After the seventh operation, M={0,1,1,4,4,5,9}M=\{0,1,1,4,4,5,9\}.

The output is 1564=61\oplus5\oplus6\oplus4=6. ::::

Limits and Notes

For 100%100\% of the testdata, 1n1051\leq n\leq 10^5, 1m1061\leq m\leq 10^6, 0ai,x<2300\leq a_i,x\lt 2^{30}.

The input size of this problem is large. Please use a fast input method.


upd 2022.7.22\text{upd 2022.7.22}: Added 99 new sets of hack testdata.

Translated by ChatGPT 5