#K34052. Array Operations
Array Operations
Array Operations
You are given an array of integers and required to perform a series of operations on it. There are two types of operations:
- Update Operation (Type 1): Replace the element at position \(i\) with a new value \(v\). The operation is represented as:
1 i v
. - Query Operation (Type 2): Compute the sum of the subarray from index \(l\) to \(r\) (inclusive). The operation is represented as:
2 l r
.
The array is 1-indexed. Initially, you are provided with the number of elements \(N\) and the number of operations \(Q\). For each query operation, output the computed sum.
inputFormat
The first line contains two integers \(N\) and \(Q\), where \(N\) is the number of elements in the array and \(Q\) is the number of operations.
The second line contains \(N\) space-separated integers representing the array elements.
The next \(Q\) lines each describe an operation in one of the following formats:
1 i v
— Update the element at index \(i\) to value \(v\).2 l r
— Query the sum of elements from index \(l\) to \(r\) (inclusive).
outputFormat
For each query operation (operation type 2), output the resulting sum on a new line.
## sample5 3
1 2 3 4 5
2 2 4
1 3 10
2 1 5
9
22
</p>