#P7447. Conditional Subtraction and Range Query
Conditional Subtraction and Range Query
Conditional Subtraction and Range Query
You are given a sequence \(a\) of length \(n\). You need to perform \(m\) operations on the sequence.
There are two types of operations:
- Operation
1 l r x
: For all indices \(i\) with \(l \leq i \leq r\), if \(a_i > x\) then update \(a_i = a_i - x\). That is, subtract \(x\) from all elements in the range \([l, r]\) that are greater than \(x\). - Operation
2 l r
: Query the subarray from index \(l\) to \(r\) and output the sum, the minimum, and the maximum value in that range.
Input constraints are such that a straightforward simulation is sufficient.
inputFormat
The first line of input contains two integers \(n\) and \(m\) — the length of the sequence and the number of operations.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) representing the sequence.
The following \(m\) lines each describe an operation in one of the following formats:
1 l r x
— For every \(i\) with \(l \le i \le r\), if \(a_i > x\) then set \(a_i = a_i - x\).2 l r
— Output the sum, minimum, and maximum of the subarray \(a_l, a_{l+1}, \dots, a_r\).
outputFormat
For each operation of type 2, output three space-separated integers representing the sum, the minimum, and the maximum of the subarray queried.
sample
5 5
1 3 5 7 9
2 1 5
1 2 4 4
2 1 5
1 3 5 2
2 3 5
25 1 9
17 1 9
9 1 7
</p>