#K45452. Range Sum and Update Queries

    ID: 27756 Type: Default 1000ms 256MiB

Range Sum and Update Queries

Range Sum and Update Queries

You are given an array of integers. Your task is to process two types of queries on the array:

  • Sum Query: Given two indices \(l\) and \(r\) (1-indexed), compute the sum of the subarray \(a[l\ldots r]\), i.e., \[ \sum_{i=l}^{r} a_i \]</p>
  • Update Query: Given an index \(i\) (1-indexed) and a value \(x\), update \(a[i]\) to \(x\).

You will be given an initial array and a sequence of queries. For each sum query, output the result on a new line.

inputFormat

The input is read from stdin and has the following format:

  1. The first line contains an integer (n), the number of elements in the array.
  2. The second line contains (n) space-separated integers representing the array (a).
  3. The third line contains an integer (q), the number of queries.
  4. The following (q) lines describe the queries. Each query is in one of the following formats:
    1 l r — a sum query, where you need to output the sum of elements from index (l) to (r) (inclusive).
    2 i x — an update query, where you update the element at index (i) to (x).

Note that indices are 1-indexed.

outputFormat

For each sum query, output the resulting sum on a new line to stdout.## sample

5
1 2 3 4 5
5
1 2 4
1 1 5
2 3 10
1 1 5
1 4 5
9

15 22 9

</p>