#P5494. Multiset Operations
Multiset Operations
Multiset Operations
You are given an initial multiset \(a\) with id \(1\). This multiset supports the following operations:
- 0 p x y: Move all elements in multiset \(p\) with values in the range \([x, y]\) to a new multiset. The new multiset's id is the next positive integer starting from \(2\) (i.e. the last produced new multiset id plus one).
- 1 p t: Insert all numbers from multiset \(t\) into multiset \(p\) and clear multiset \(t\). It is guaranteed that multiset \(t\) will not be used in later operations.
- 2 p x q: Insert \(x\) copies of the number \(q\) into multiset \(p\).
- 3 p x y: Query the number of elements in multiset \(p\) with values in the range \([x, y]\).
- 4 p k: Query the \(k\)-th smallest element in multiset \(p\). If it does not exist, output
-1
.
You are to process a sequence of operations. For query operations (types 3 and 4), output the result on a new line.
inputFormat
The first line of input contains an integer \(n\), the number of operations. The next \(n\) lines each contain an operation in one of the following formats:
0 p x y
1 p t
2 p x q
3 p x y
4 p k
outputFormat
For each query operation (types 3 and 4), output the corresponding result on a separate line.
sample
6
2 1 5 3
2 1 3 2
3 1 2 3
4 1 4
0 1 2 2
3 1 2 3
8
3
5
</p>