#C10570. Segment Tree Query Processor
Segment Tree Query Processor
Segment Tree Query Processor
You are given an array of integers and a sequence of queries to perform on the array. There are two types of queries:
- Update Query (type 1): Change the value at a given index to a new value.
- Sum Query (type 2): Compute the sum of the elements in the range \(l\) to \(r\) (inclusive).
Your task is to implement a segment tree which supports these two operations efficiently. The segment tree should allow you to update an element and answer range sum queries quickly.
Note: The range provided in the sum query is inclusive of both endpoints.
inputFormat
The input is given from stdin
and has the following format:
- An integer \(n\), the number of elements in the array.
- \(n\) space-separated integers representing the array.
- An integer \(q\), the number of queries.
- \(q\) lines follow, each containing three integers:
type x y
. Iftype
is 1, then update the element at indexx
toy
. Iftype
is 2, then output the sum of the elements from indexx
toy
(inclusive).
outputFormat
For each query of type 2, output the computed range sum on a separate line to stdout
.
5
1 2 3 4 5
5
2 0 2
1 1 10
2 0 2
2 1 3
1 4 6
6
14
17
</p>