#K89127. Array Processor
Array Processor
Array Processor
You are given an array of n integers. Your task is to perform q queries on the array. There are two types of queries:
- Update Query: Change the value at a specific index.
- Range Sum Query: Calculate the sum of a subarray from index l to r (both inclusive). Mathematically, for a query of the second type, you need to output \(\sum_{i=l}^{r}{a_i}\).
All indices are 1-indexed. Make sure your solution reads input from stdin
and writes the output to stdout
.
inputFormat
The input is given via stdin
in the following format:
- The first line contains two integers n and q, representing the number of elements in the array and the number of queries, respectively.
- The second line contains n space-separated integers, representing the array.
- The following q lines each contain three integers
op l r
whereop
indicates the type of query. Ifop = 1
, then update the element at indexl
to the new valuer
. Ifop = 2
, then output the sum of elements from indexl
tor
.
outputFormat
For each query of type 2, output the corresponding sum on a new line to stdout
. If there are no sum queries, output nothing.
5 5
1 2 3 4 5
2 1 3
1 3 10
2 2 5
1 5 7
2 1 5
6
21
24
</p>