#C4125. Efficient Array Query Processor
Efficient Array Query Processor
Efficient Array Query Processor
You are given an array of n integers and need to perform q queries on it. There are two types of queries:
- Update Query: Modify the element at a given position to a new value. The query is of the form
1 i v
, wherei
is the 1-indexed position andv
is the new value. - Sum Query: Compute the sum of the subarray from index
l
tor
(inclusive). The query is of the form2 l r
. The sum is defined as \(\sum_{i=l}^{r} a_i\).
Process the queries sequentially and output the result for each sum query on a separate line.
inputFormat
The input is given via standard input (stdin).\n\nThe first line contains two integers (n) and (q), representing the number of elements in the array and the number of queries respectively.\nThe second line contains (n) space-separated integers representing the elements of the array.\nEach of the next (q) lines contains three integers describing a query. For an update query, the format is "1 i v"; for a sum query, the format is "2 l r".
outputFormat
For each sum query (type 2), output the computed sum of the subarray from index (l) to (r) on a new line. The output is sent to standard output (stdout).## sample
5 6
1 2 3 4 5
2 1 3
1 2 10
2 2 5
1 3 6
2 1 4
2 1 5
6
22
21
26
</p>