#K67442. Range Sum Queries with Updates
Range Sum Queries with Updates
Range Sum Queries with Updates
In this problem, you are given an array \(A\) of \(n\) integers. You will process \(q\) queries on the array. The queries are of two types:
- Update Query: This query is represented as
1 i v
and it updates the element at index \(i\) to \(v\), i.e., \(A[i] = v\). - Range Sum Query: This query is represented as
2 l r
and it asks for the sum of the array elements from index \(l\) to \(r\) (inclusive). The sum is defined as \(S(l, r)=\sum_{i=l}^{r}A[i]\).
Your task is to process all the queries and output the answer for each range sum query.
inputFormat
The input is given via standard input (stdin) and has the following format:
n q A[0] A[1] ... A[n-1] query_1 query_2 ... query_q
- The first line contains two integers \(n\) and \(q\), where \(n\) is the number of elements in the array and \(q\) is the number of queries.
- The second line contains \(n\) integers representing the initial values of the array \(A\).
- Each of the following \(q\) lines represents a query. A query can be one of the following two types:
1 i v
: Update the array at index \(i\) to the value \(v\).2 l r
: Compute the sum of the subarray \(A[l...r]\). Indices are 0-based.
outputFormat
For each range sum query (queries of type 2), output the resulting sum on a new line to standard output (stdout).## sample
5 4
1 2 3 4 5
2 0 2
1 1 6
2 1 3
2 3 4
6
13
9
</p>