#P9998. [Ynoi2000] rfrqwq

[Ynoi2000] rfrqwq

Problem Description

Given a sequence aa of length nn, each position contains an integer in [1,n][1,n].

Define f(i,j)f(i,j) as the number of integers xx such that ix<ji \le x < j and axax+1a_x \ne a_{x+1}.

There are mm operations:

1 l r x: Set all elements in the interval [l,r][l,r] to xx.

2 l r x: Query, within the interval [l,r][l,r], the sum of f(i,j)f(i,j) over all pairs li<jrl \le i < j \le r such that ai=aj=xa_i = a_j = x.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers separated by spaces, representing the sequence aa.

Then follow mm lines, each containing four integers opt,l,r,xopt, l, r, x separated by spaces, representing an operation.

Output Format

For each operation of type 22, output one line containing one integer, the answer.

10 10
2 1 2 1 8 3 2 1 2 2
2 6 9 2
2 3 10 2
2 2 10 2
2 1 3 2
2 4 10 1
1 2 4 2
2 3 10 2
2 2 7 1
2 2 7 2
2 3 6 2
2
20
20
2
4
30
0
9
0

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: ccz181078, Data: ccz181078.

For 20%20\% of the testdata, 1n,m10001 \le n, m \le 1000.

For another 20%20\% of the testdata, there are no type 11 operations.

For another 10%10\% of the testdata, the operation types are in [1,2][1,2], and ai,xa_i, x are generated uniformly at random in [1,100][1,100]. The two endpoints of the interval [l,r][l,r] are integers generated uniformly at random from [1,n][1,n]. If l>rl > r after generation, swap them.

For another 30%30\% of the testdata, 1n,m1051 \le n, m \le 10^5.

For 100%100\% of the testdata, 1n,m5×1051 \le n, m \le 5 \times 10^5, 1lrn1 \le l \le r \le n, 1ai,xn1 \le a_i, x \le n, and all inputs are integers.

Translated by ChatGPT 5