#P10923. [2015杭电多校]Gorgeous Sequence

[2015杭电多校]Gorgeous Sequence

Gorgeous Sequence

Problem Description

There is a sequence aa of length nn. We use aia_i to denote the ii-th element in this sequence. You should do the following three types of operations to this sequence. 0 x y t0\ x\ y\ t: For every xiyx \le i \le y, we use min(ai,t)min(a_i, t) to replace the original aia_i's value. 1 x y1\ x\ y: Print the maximum value of aia_i that xiyx \le i \le y. 2 x y2\ x\ y: Print the sum of aia_i that xiyx \le i \le y.

Input

The first line of the input is a single integer TT, indicating the number of testcases. The first line contains two integers nn and mm denoting the length of the sequence and the number of operations. The second line contains nn separated integers a1,,ana_1, \ldots, a_n (1in,0ai<231\forall 1 \le i \le n, 0 \le a_i < 2^{31}). Each of the following mm lines represents one operation (1xyn,0t<2311 \le x \le y \le n, 0\le t < 2^{31}). It is guaranteed that T=100T=100, n1000000, m1000000\sum n \le 1000000, \ \sum m \le 1000000.

Output

For every operation of type 11 or 22, print one line containing the answer to the corresponding query.

Sample Input

1
5 5
1 2 3 4 5
1 1 5
2 1 5
0 3 5 3
1 1 5
2 1 5

Sample Output

5
15
3
12

Hint

Please use efficient IO method

Author

XJZX

Source

2015 Multi-University Training Contest 2