#C2335. Array Operations and Extremes
Array Operations and Extremes
Array Operations and Extremes
You are given ( T ) test cases. For each test case, you are provided with an array of ( N ) integers. Then ( Q ) operations follow. Each operation is represented by three integers ( L ), ( R ), and ( V ), which means that ( V ) is added to each of the array elements in the range from ( L ) to ( R ) (inclusive, 1-indexed).
After all operations are performed on the array, determine the maximum and minimum values in the array along with the smallest index where each occurs. Mathematically, for an array ( A ) and an operation ( (L, R, V) ), update
[
A[i] = A[i] + V, \quad \text{for } L \leq i \leq R.
]
Then compute
[
\text{max} = \max_{1 \leq i \leq N} A[i], \quad \text{and} \quad \text{min} = \min_{1 \leq i \leq N} A[i].
]
Let ( i_{max} ) and ( i_{min} ) be the smallest indices such that ( A[i_{max}] = \text{max} ) and ( A[i_{min}] = \text{min} ), respectively.
Output the result for each test case on two separate lines: the first line contains ( i_{max} ) and the maximum value, and the second line contains ( i_{min} ) and the minimum value.
inputFormat
The input is read from standard input (stdin). The first line contains an integer ( T ) representing the number of test cases. Each test case consists of the following:
- The first line contains an integer \( N \), the number of elements in the array.
- The second line contains \( N \) space-separated integers.
- The third line contains an integer \( Q \), the number of operations.
- Each of the next \( Q \) lines contains three space-separated integers \( L \), \( R \) and \( V \), representing an operation to add \( V \) on the segment from \( L \) to \( R \) (inclusive).
outputFormat
For each test case, output two lines to standard output (stdout):
- The first line should contain two integers: the 1-indexed position (smallest index if there are ties) and the maximum value of the modified array.
- The second line should contain two integers: the 1-indexed position (smallest index if there are ties) and the minimum value of the modified array.
2
5
1 2 3 4 5
2
1 3 2
2 5 -1
4
1 -1 0 2
3
1 2 3
2 4 -4
1 4 1
3 4
1 3
1 5
3 -3
</p>