#C6383. Range Sum Queries with Updates

    ID: 50137 Type: Default 1000ms 256MiB

Range Sum Queries with Updates

Range Sum Queries with Updates

You are given an array of integers and a series of queries to perform on the array. There are two types of queries:

  1. Update Query: "1 x y". Update the element at index (x) to (y).
  2. Sum Query: "2 x y". Compute the sum (S = \sum_{i=x}^{y} a_i), where (a_i) denotes the (i)th element of the array.

The array indices are 1-indexed. The input is provided via STDIN, and your program should output the result for each sum query (type 2) on a separate line via STDOUT.

Example:
For the input:
5 5 1 2 3 4 5 2 1 3 1 3 10 2 1 3 2 2 5 1 5 6
The output should be:
6 13 21

inputFormat

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

  • The first line contains two space-separated integers (n) and (q), representing the number of elements in the array and the number of queries, respectively.
  • The second line contains (n) space-separated integers representing the array elements.
  • Each of the next (q) lines contains three space-separated integers describing a query. For an update query, the format is "1 x y"; for a sum query, the format is "2 x y".

outputFormat

For each query of type "2 x y", output the computed range sum on a new line via STDOUT.## sample

5
5
1 2 3 4 5
2 1 3
1 3 10
2 1 3
2 2 5
1 5 6
6

13 21

</p>