#C6006. Dynamic Range Sum Queries
Dynamic Range Sum Queries
Dynamic Range Sum Queries
You are given an integer sequence of length \(n\) and \(q\) operations to perform on the sequence. There are two types of operations:
- Update Operation: Format \(1\ index\ value\). This sets the element at the given \(index\) (0-indexed) in the sequence to \(value\).
- Range Sum Query: Format \(2\ left\ right\). This asks you to compute the sum of the elements from index \(left\) to index \(right\) (inclusive).
Constraints:
- \(1 \le n, q \le 10^5\)
- \(1 \le a_i \le 10^9\) for each element in the sequence.
You are required to process the operations efficiently. When performing a range sum query, output the result on a new line.
inputFormat
The input is read from stdin and has the following format:
n q a1 a2 a3 ... an op1 op2 ... opq
Here, the first line contains two integers \(n\) and \(q\). The second line has \(n\) space-separated integers representing the initial sequence. Each of the following \(q\) lines represents an operation in one of the following formats:
1 index value
— Update operation.2 left right
— Range sum query.
outputFormat
The output should be written to stdout. For each range sum query, output a single line with the computed sum.
## sample5 4
1 2 3 4 5
2 1 3
1 2 10
2 1 3
2 0 4
9
16
22
</p>