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 SS that allows duplicates, supporting:

  • Insert [L,R][L, R], i.e., insert L,L+1...,RL, L + 1 ... , R, these RL+1R - L + 1 numbers.

  • Query Sort(S)Sort(S).


The definition of Sort(S)Sort(S) is:

We sort the elements in SS from small to large using quicksort, denoted as a1,a2...ana_1, a_2 ... a_n.

Then, $Sort(S) = \bigoplus \limits_{i = 2}^n (a_i^2 - a_{i - 1}^2)$, where \bigoplus denotes XOR.

For the definition of XOR, please consult Baidu.

Input Format

The first line contains an integer qq.

The next qq lines are either 1  l  r1\;l\;r, meaning insert [l,r][l, r], or 22, 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:

SS contains only one number, so return 00.


Constraints:

For the 3030 points testdata, q100q \leqslant 100.

For the 5050 points testdata, q5104q \leqslant 5 * 10^4.

For the other 2020 points testdata, L=RL = R.

For the 100100 points testdata, q3105q \leqslant 3 * 10^5, 1LR1091 \leqslant L \leqslant R \leqslant 10^9.

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