#P2496. [SDOI2012] 体育课

[SDOI2012] 体育课

Description

It is time for another PE class. There are nn students standing in a row. They all dislike the student at the first position. For any student behind the first one, if they are taller than the first student, they gain a happiness value equal to their height minus the height of the first student. If a student is shorter than the first student, their happiness value is 00.

Now the PE teacher comes with magical powers and can perform the following three operations:

  1. Query the maximum happiness value within a given interval.
  2. Swap two students.
  3. Select an interval and add tt to the first person in the interval, 2t2t to the second, 3t3t to the third, and so on.

However, the teacher cannot count well, so he asks you to answer each query.

For clarity, for an interval [l,r][l, r], define the happiness of position ii (lirl \le i \le r) as max(0,aial)\max(0, a_i - a_l). Operation 11 asks for the maximum of these values over i[l,r]i \in [l, r].

Input Format

The first line contains two integers n,mn, m, the number of students and the number of operations.

The second line contains nn integers, the heights aia_i of the students in order.

Each of the following mm lines starts with an integer typetype indicating the operation:

  • If type=1type = 1, then two integers l,rl, r follow, asking for the maximum happiness value in interval [l,r][l, r] as defined above.
  • If type=2type = 2, then two integers a,ba, b follow, indicating to swap the students at positions aa and bb.
  • If type=3type = 3, then three integers l,r,tl, r, t follow, indicating that for every ii with lirl \le i \le r, add (il+1)×t(i - l + 1) \times t to aia_i.

Output Format

For each query, output the answer to every operation 11 in order.

6 7
109 827 100 530 10 826
3 1 6 1
2 2 6
1 2 4
1 2 3
2 2 6
1 2 6
1 2 5
722
722
722
719

Hint

Constraints

  • For 20%20\% of the testdata, 1n,m5×1031 \le n, m \le 5 \times 10^3.
  • Additionally, in 10%10\% of the testdata, there is no operation 33.
  • Additionally, in 20%20\% of the testdata, there is no operation 22.
  • For 100%100\% of the testdata, 1n,m1051 \le n, m \le 10^5, 0t1040 \le t \le 10^4, 1ai1081 \le a_i \le 10^8.

Translated by ChatGPT 5