#C10570. Segment Tree Query Processor

    ID: 39790 Type: Default 1000ms 256MiB

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:

  1. An integer \(n\), the number of elements in the array.
  2. \(n\) space-separated integers representing the array.
  3. An integer \(q\), the number of queries.
  4. \(q\) lines follow, each containing three integers: type x y. If type is 1, then update the element at index x to y. If type is 2, then output the sum of the elements from index x to y (inclusive).

outputFormat

For each query of type 2, output the computed range sum on a separate line to stdout.

## sample
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>