#C1302. Query Processor: Range Sum and Update
Query Processor: Range Sum and Update
Query Processor: Range Sum and Update
You are given an array of n integers and q queries. Each query is one of two types:
- Type 1: Update the array at a specified position. The query is given as
1 x v
, which means update the value at indexx
tov
. - Type 2: Calculate the sum of a subarray. The query is given as
2 x y
, which means compute the sum $$ S = \sum_{i=x}^{y} a_i $$ where the array is 1-indexed.
Perform each query in the order they are given. For type 2 queries, output the computed sum on a new line.
inputFormat
The first line contains two integers n and q, where n is the length of the array and q is the number of queries.
The second line contains n space-separated integers representing the initial array.
Each of the next q lines contains three integers describing a query.
If the first integer is 1, the query is of the form 1 x v
and indicates that the element at index x
should be updated to v
.
If the first integer is 2, the query is of the form 2 x y
and asks for the sum of elements from index x
to y
(inclusive).
outputFormat
For every query of type 2, output the sum of the specified subarray on a new line.
## sample5 3
1 2 3 4 5
2 1 3
1 2 10
2 1 3
6
14
</p>