#C968. Array Operations with Updates and Range Sums
Array Operations with Updates and Range Sums
Array Operations with Updates and Range Sums
You are given an array of N integers and tasked with executing Q operations on the array. There are two types of operations:
- Update Operation: Given in the form
1 x v
, update the element at position x to value v. - Range Sum Query: Given in the form
0 l r
, compute the sum of elements in the subarray from index l to r (both inclusive). Mathematically, for an array a, the answer is \(\sum_{i=l}^{r} a_i\).
Your task is to process the operations in the order they are given and output the result of each range sum query.
inputFormat
The input is read from stdin
in the following format:
N a1 a2 ... aN Q op1 op2 ... opQ
Here, N is the number of elements in the array, followed by a line containing N space-separated integers representing the array. Q is the number of operations. Each of the next Q lines represents an operation, which can either be an update (1 x v
) or a range sum query (0 l r
). The array indices are 1-indexed.
outputFormat
For every range sum query (operations starting with 0), output the sum of the specified range on a separate line. The output is printed to stdout
.
5
1 2 3 4 5
4
0 1 3
1 2 10
0 1 3
0 2 5
6
14
22
</p>