#P4513. 小白逛公园

小白逛公园

Description

Near Xiaoxin’s home there is a “Park Road,” along one side of which nn parks are lined up from south to north. Xiaobai is dazzled and is not sure which parks to visit.

At the beginning, Xiaobai assigns a score to each park based on its scenery. For convenience, every time they go for a walk, Xiaoxin specifies a range, and Xiaobai may choose a contiguous sequence of parks between the aa-th and bb-th parks (inclusive). Of course, Xiaobai wants the sum of the selected parks’ scores to be as large as possible. Meanwhile, as some parks’ landscapes change, Xiaobai’s scores may also change.

So please help Xiaobai choose the parks.

Input Format

  • The first line contains two integers nn and mm, representing the number of parks and the total number of operations (walks or score changes).
  • The next nn lines each contain one integer, giving the initial score that Xiaobai assigns to each park in order.
  • The next mm lines each contain three integers. The first integer kk is 11 or 22.
    • If k=1k = 1, Xiaoxin is taking Xiaobai out to play. The next two integers aa and bb give the selectable range of parks (1a,bn)(1 \le a, b \le n). The testdata may contain cases where a>ba > b, in which case you should swap them.
    • If k=2k = 2, Xiaobai changes the score of a park. The next two integers pp and ss mean the score of the pp-th park becomes ss (1s1000)(1 \le |s| \le 1000).

Output Format

For each walk, output one line containing a single integer: the maximum possible sum of scores of the parks Xiaobai can select.

5 3
1
2
-3
4
5
1 2 3
2 2 -1
1 2 3
2
-1

Hint

Constraints

For 100%100\% of the testdata, 1n5×1051 \le n \le 5 \times 10^5, 1m1051 \le m \le 10^5, and all scores are integers with absolute value at most 10001000.

Translated by ChatGPT 5