#K78482. Array Operations
Array Operations
Array Operations
You are given an array of n integers and q operations. The operations can be of three types:
- update i x: Update the element at index i (0-indexed) with the value x.
- sum l r: Output the sum of elements from index l to r (inclusive).
- min l r: Output the minimum element from index l to r (inclusive).
Each update
operation does not produce output. Your task is to process all the operations in the given order and output the results of the sum
and min
queries.
The formulas used in this problem can be represented in \( \LaTeX \) as follows:
- Subarray sum: \( S = \sum_{i=l}^{r} a_i \)
- Subarray minimum: \( m = \min\{a_l, a_{l+1}, \dots, a_r\} \)
inputFormat
The first line contains two integers n and q separated by a space.
The second line contains n integers, representing the initial array.
Then, q lines follow, each containing one of the three operation commands in one of the following forms:
update i x
sum l r
min l r
All indices are 0-indexed.
outputFormat
For each sum
and min
query, output the result on a new line in the order they appear.
5 6
1 2 3 4 5
sum 0 2
min 1 3
update 2 10
sum 2 4
min 0 4
sum 0 4
6
2
19
1
22
</p>