#K81467. Range Update and Extreme Query
Range Update and Extreme Query
Range Update and Extreme Query
Given an array of n integers and q operations, perform the following updates:
Each operation is described by three integers \(L\), \(R\), and \(X\), meaning that every element in the subarray from index \(L\) to \(R\) (1-indexed) is increased by \(X\). After processing all operations, output the maximum and minimum value from the final updated array.
Hint: Use a difference array to apply range updates efficiently. The update to the original array can be computed using the formula:
\[ diff[i] = \begin{cases} X & \text{if } i = L-1 \\ -X & \text{if } i = R \text{ and } R < n \\ 0 & \text{otherwise} \end{cases} \]
inputFormat
Input Format:
- The first line contains two space-separated integers, n and q, where n is the number of elements in the array and q is the number of update operations.
- The second line contains n space-separated integers representing the array.
- The next q lines each contain three space-separated integers \(L\), \(R\), and \(X\) describing an operation.
outputFormat
Output Format:
Print two space-separated integers: the maximum and the minimum values in the final updated array.
## sample5 3
1 2 3 4 5
1 3 2
2 5 1
3 4 3
9 3
</p>