#P51430. [COCI 2021.2] Sjeckanje

[COCI 2021.2] Sjeckanje

Description

Paula likes to prepare stir fry. In order to make it as yummy as possible, she needs to chop a sequence of nn integers into segments of the maximum total value.

The valuevalue of a segment is the difference of its maximum and minimum. The value of a chopped sequence is the sum of the values of the segments.

For example if we chop the sequence [1,4,1,5,3,6][1,4,1,5,3,6] into segments [1,4,1][1,4,1] and [5,3,6][5,3,6], the total value is (41)+(63)=6(4 − 1) + (6 − 3) = 6.

There will be qq updates of the form “add xx to the elements on indices l,l+1,,rl, l + 1, \ldots , r”. After each update, answer the query “What is the maximum possible value of the chopped sequence?”.

Input

The first line contains integers nn and qq (1n,q200 000)(1 \le n, q \le 200\ 000), the length of the sequence and the number of updates.

The second line contains nn integers aia_i (108ai108)(−10^8 \le a_i \le 10^8), the sequence Paula needs to chop.

Each of the following qq lines contains integers l,rl, r (1lrn)(1 \le l \le r \le n), and xx (108x108)(−10^8 \le x \le 10^8), describing an update.

Output

Output qq lines, the maximum possible value of the sequence after each update.

Example 1

4 3
1 2 3 4
1 2 1
1 1 2
2 3 1

2
2
0

Possible optimal choppings after each update are respectively: [2,3,3,4][2,3,3,4],[4,3][3,4] [4,3] [3,4], and [4,4,4,4][4,4,4,4].

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

Scoring

Subtask Constraints Points
11 n,q200n,q\le 200 15/11015/110
22 n,q3×103n,q\le 3\times 10^3 40/11040/110
33 No additional constraints. 55/11055/110