#P6794. [SNOI2020] 水池

[SNOI2020] 水池

Description

There is a long, narrow pool that can be divided into nn cells. Cell ii and cell i+1i+1 are adjacent, separated by an adjustable barrier with height hih_i. To the left of cell 11 and to the right of cell nn are infinitely high pool walls. Initially, there is no water in the pool.

Now perform qq operations. There are four types of operations:

  • 0 i x h: Pour water into cell xx until the water surface height in that cell is not less than hh (if the current water surface height is already at least hh, nothing happens).
  • 1 i x: Open the drain at the bottom of cell xx until the water in that cell is completely drained, then close the drain.
  • 2 i x h: Increase the height of the barrier to the right of cell xx to hh (do not change existing water levels; it is guaranteed that the barrier height will not decrease).
  • 3 i x: Query the water surface height in cell xx.

Here, ii means that this operation is based on the state after the ii-th operation; i=0i=0 means it is based on the initial state. In other words, the operations need to be persistent.

Input Format

The first line contains two non-negative integers n,qn,q, representing the number of cells in the pool and the number of operations.
The next line contains n1n-1 positive integers hih_i, representing the initial heights of the barriers.
Then follow qq lines, each describing one operation.

Output Format

For each operation of type 3, output one line with one integer representing the answer.

4 9
1 3 2
0 0 4 2
3 1 1
0 2 4 3
3 3 1
0 4 4 4
3 5 1
2 6 1 4
1 7 4
3 8 1
0
0
4
4

Hint

Sample Explanation

For sample 11:

Constraints

For all testdata, 1n,q2×1051\le n,q\le 2\times 10^5, 0hi1090\le h_i\le 10^9.

  • For 10%10\% of the testdata, n500n \le 500.
  • For another 20%20\%, there is no operation 1, and ii increases consecutively starting from 00 (persistence is not needed).
  • For another 20%20\%, there is no operation 1.
  • For another 20%20\%, and ii increases consecutively starting from 00 (persistence is not needed).
  • For the remaining 30%30\% of the testdata, there are no special restrictions.

Translated by ChatGPT 5