#P7402. [COCI 2020/2021 #5] Sjeckanje

[COCI 2020/2021 #5] Sjeckanje

Description

You are given an array aa containing nn integers. Then there are qq updates. Each update gives integers l,r,xl, r, x, meaning to add xx to all elements in [l,r][l, r].

Define the weight of an interval as the maximum value in the interval minus the minimum value in the interval. Now you need to split array aa into several consecutive intervals. Define the weight of an array that has been split into several intervals as the sum of the weights of all its intervals. For each update, find the maximum possible array weight among all ways to split the array after that update.

Input Format

The first line contains integers n,qn, q, representing the length of the array and the number of updates.

The second line contains nn integers aia_i.

The next qq lines each contain integers l,r,xl, r, x, describing an update.

Output Format

Output qq lines. On the ii-th line, output the maximum possible array weight among all splits of array aa after the ii-th update.

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

Hint

Explanation of Sample 1

Number of updates Array after this update One optimal split Array weight
11 [2,3,3,4][2,3,3,4] 22
22 [4,3,3,4][4,3,3,4] [4,3],[3,4][4,3],[3,4]
33 [4,4,4,4][4,4,4,4] 00

Constraints and Notes

This problem uses bundled testdata.

Subtask Points Constraints and notes
11 1515 1n,q2001 \le n, q \le 200
22 4040 1n,q30001 \le n, q \le 3000
33 5555 None

For 100%100\% of the testdata, 1n,q2×1051 \le n, q \le 2 \times 10^5, 108ai,x108-10^8 \le a_i, x \le 10^8, and 1lrn1 \le l \le r \le n.

Additional Notes

The scoring follows the original COCI problem settings, with a full score of 110110.

Translated from COCI2020-2021 CONTEST #5 T5 Sjeckanje.

Translated by ChatGPT 5