#C10517. Array Operations
Array Operations
Array Operations
You are given an array of integers and a sequence of operations to perform on the array. There are two types of operations:
- Update Operation (Type 1): Update the element at index x to a new value y, i.e. \(a[x] = y\).
- Sum Operation (Type 2): Calculate the sum of the elements in the subarray from index x to y (inclusive), i.e. compute \(\sum_{i=x}^{y} a[i]\).
The operations are performed in the given order. For every sum operation, you should output the result (each on its own line). If there are no sum operations, then nothing should be printed.
Note: All indexing is 0-based.
inputFormat
The first line contains two integers n and m, where n is the number of elements in the array and m is the number of operations.
The second line contains n space-separated integers representing the array.
The next m lines each contain three integers: type, x and y. If type is 1, update a[x] to y. If type is 2, output the sum of elements from index x to y (inclusive).
outputFormat
For each operation of type 2, output the resulting sum on a separate line. If there are no sum operations, the output will be empty.
## sample5 3
1 3 5 7 9
2 1 3
1 2 4
2 2 4
15
20
</p>