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

[Ynoi Easy Round 2019] 黑川赤音

Background

Problem Description

You are given an array aa and nn sets. Initially, the ii-th set contains only one element ii. Each element in a set corresponds to an index of the array.

Define the number of equal values of an element ii in a set SS as F(S,i)F(S,i), which is the number of elements jj in SS such that a[i]=a[j]a[i] = a[j].

Define the kk-weight of a set SS as: for all iSi \in S and for all jSj \in S, count how many ordered pairs (i,j)(i,j) satisfy F(S,i)+F(S,j)kF(S,i) + F(S,j) \le k. Here, ii may equal jj, and (i,j)(i,j) and (j,i)(j,i) are considered different.

You need to perform mm operations of two types:

1 x y: Move all elements in set yy into set xx, then clear set yy. It is guaranteed that both set xx and set yy are non-empty before the operation.

2 x l r k: Query the kk-weight of set xx when only keeping the elements whose indices are in [l,r][l,r]. Each query is independent and does not modify any set.

Input Format

The first line contains two integers separated by spaces, denoting n,mn,m.

The second line contains nn integers, denoting the array.

The next mm lines each describe one operation in the format given above.

Output Format

For each operation of type 22, 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 10%10\% of the testdata, n,m100n,m \le 100.

For another 20%20\% of the testdata, n,m10000n,m \le 10000.

For another 20%20\% of the testdata, the queried kk does not change.

For 100%100\% of the testdata, n105n \le 10^5, m2×105m \le 2 \times 10^5, 0ai,km0 \le a_i,k \le m, 1lrn1 \le l \le r \le n, 1x,yn1 \le x,y \le n.

Translated by ChatGPT 5