#P6749. 『MdOI R3』Yoshino

    ID: 5053 远端评测题 1000~2000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>线段树O2优化树套树洛谷月赛

『MdOI R3』Yoshino

Description

Yoshino gives you a sequence of length nn, where the ii-th term is aia_i.

Now Yoshino will perform mm operations on the sequence.

There are two types of operations:

  • 1 l r x1\ l\ r\ x: Yoshino changes the numbers with indices in the interval [l,r][l,r] into an arithmetic progression starting from xx with common difference 11.

  • 22: Yoshino needs to query the number of inversion pairs in the entire sequence. An inversion pair is a pair (i,j)(i,j) such that i<ji<j and ai>aja_i>a_j.

Input Format

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

The second line contains nn integers; the ii-th one is aia_i.

The next mm lines each describe an operation, with the meaning as stated above.

Output Format

For each query, output one integer per line as the answer.

3 3
3 2 1 
2 
1 1 3 1 
2 
3 
0 

Hint

[Sample Explanation]

The first operation is a query. At this time there are three inversion pairs: (1,3),(2,3),(1,2)(1,3),(2,3),(1,2), so the answer is 33.

After the second operation (the modification), the sequence becomes 1 2 31\ 2\ 3.

The third operation is a query. At this time there are no inversion pairs in the sequence, so the answer is 00.

You can get more samples here.


[Constraints]

This problem uses bundled testdata.

Subtask ID n,mn,m\le Special Condition Score Time Limit
11 500500 None 1010 1s1s
22 3×1033\times 10^3
33 3×1043\times 10^4 The modification length is 11 1515 2s2s
44 The maximum value in the sequence never exceeds 1515 2020
55 The odd-numbered operation 11 is guaranteed to be 1 1 n 11\ 1\ n\ 1
66 No special restrictions 2525

For all testdata, 1n,m,ai3×1041\le n,m,a_i\le 3\times 10^4, 1lrn1\le l\le r\le n, 1x3×104r+l1\le x\le 3\times 10^4-r+l.

Translated by ChatGPT 5