#C7531. Taco: Array Query Processing
Taco: Array Query Processing
Taco: Array Query Processing
You are given an array of ( n ) integers and ( q ) queries. There are two types of queries:
1. Update Query: Query of the form 1 i x
instructs you to update the ( i^{th} ) element of the array (1-indexed) to ( x ).
2. Sum Query: Query of the form 2 l r
asks for the sum of the array elements from index ( l ) to ( r ) (inclusive).
For every query of the second type, you need to print the sum.
Formally, if the array is ( a_1, a_2, \ldots, a_n ) and a sum query is given as:
[
\sum_{j=l}^{r} a_j
]
you should calculate and return this sum.
Input is read from standard input and output is printed to standard output. Make sure your solution is efficient enough to handle the constraints.
inputFormat
The first line contains two integers ( n ) and ( q ) separated by a space.
The second line contains ( n ) space-separated integers representing the array.
The next ( q ) lines each contain a query that is either in the format 1 i x
(update query) or 2 l r
(sum query).
outputFormat
For each sum query (type 2), output the sum of the elements in the specified segment on a separate line.## sample
5 5
1 2 3 4 5
2 1 3
1 3 10
2 1 3
1 1 -2
2 1 5
6
13
19
</p>