#P13130. [Ynoi Easy Round 2019] 黑川赤音
[Ynoi Easy Round 2019] 黑川赤音
Background

Problem Description
You are given an array and sets. Initially, the -th set contains only one element . Each element in a set corresponds to an index of the array.
Define the number of equal values of an element in a set as , which is the number of elements in such that .
Define the -weight of a set as: for all and for all , count how many ordered pairs satisfy . Here, may equal , and and are considered different.
You need to perform operations of two types:
1 x y: Move all elements in set into set , then clear set . It is guaranteed that both set and set are non-empty before the operation.
2 x l r k: Query the -weight of set when only keeping the elements whose indices are in . Each query is independent and does not modify any set.
Input Format
The first line contains two integers separated by spaces, denoting .
The second line contains integers, denoting the array.
The next lines each describe one operation in the format given above.
Output Format
For each operation of type , output one line with one integer, denoting the answer to the query.
10 30
5 4 1 2 3 2 1 4 2 2
2 1 1 5 3
2 3 1 7 1
2 9 1 7 1
2 1 1 1 2
2 1 1 10 1
2 9 9 9 3
1 3 10
2 3 1 1 2
1 1 8
2 5 5 5 2
2 1 1 1 2
1 9 1
2 6 5 5 2
2 2 4 6 3
2 7 1 5 1
2 2 6 8 3
2 2 1 9 3
2 9 9 9 1
1 2 4
2 2 3 7 2
1 6 3
2 7 3 5 1
1 2 5
2 9 1 9 2
2 2 3 7 2
1 6 7
1 2 6
1 2 9
2 2 1 7 1
2 2 1 3 1
1
0
0
1
0
1
0
1
1
0
0
0
0
1
0
1
0
9
4
0
0
Hint
Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477.
For of the testdata, .
For another of the testdata, .
For another of the testdata, the queried does not change.
For of the testdata, , , , , .
Translated by ChatGPT 5