luogu#P5105. 不强制在线的动态快速排序
不强制在线的动态快速排序
Background
Xiyue recently learned quicksort, but she soon thought: if we need to sort dynamically, what should we do?
Problem Description
To study this problem, Xiyue proposed a very simple question.
Xiyue wants to maintain a multiset that allows duplicates, supporting:
-
Insert , i.e., insert , these numbers.
-
Query .
The definition of is:
We sort the elements in from small to large using quicksort, denoted as .
Then, $Sort(S) = \bigoplus \limits_{i = 2}^n (a_i^2 - a_{i - 1}^2)$, where denotes XOR.
For the definition of XOR, please consult Baidu.
Input Format
The first line contains an integer .
The next lines are either , meaning insert , or , meaning one query.
Output Format
For each query, output one line with one answer.
2
1 1 1
2
0
10
1 22 27
1 50 55
1 82 87
1 2 7
2
1 47 52
1 62 67
1 61 66
1 41 46
2
2515
2141
Hint
Explanation for Sample 1:
contains only one number, so return .
Constraints:
For the points testdata, .
For the points testdata, .
For the other points testdata, .
For the points testdata, , .
The testdata is guaranteed to have gradients. It may be slightly sensitive to constants, so please optimize your constants as much as possible.
Translated by ChatGPT 5