#4507. HDU5306-Gorgeous Sequence(华丽的序列)

    ID: 4507 传统题 3000ms 128MiB 尝试: 38 已通过: 2 难度: 9 上传者: 标签>数据结构高级数据结构线段树难度省选/NOI-吉如一线段树

HDU5306-Gorgeous Sequence(华丽的序列)

Problem - 5306: Gorgeous Sequence

Problem Description

There is a sequence a a of length n n . We use ai a_i to denote the i i -th element in this sequence. You should do the following three types of operations to this sequence:

  • 0 x y t 0\ x\ y\ t : For every xiy x \le i \le y , we use min(ai,t) \min(a_i, t) to replace the original ai a_i 's value.
  • 1 x y 1\ x\ y : Print the maximum value of ai a_i that xiy x \le i \le y .
  • 2 x y 2\ x\ y : Print the sum of ai a_i that xiy x \le i \le y .

Input

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

Output

For every operation of type 1 or 2, 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
9

Hint

Please use efficient IO method.

Author

XJZX

Source

HDU Online Judge

}