#K81237. Array Updates and Range Sum Queries

    ID: 35709 Type: Default 1000ms 256MiB

Array Updates and Range Sum Queries

Array Updates and Range Sum Queries

You are given an array of integers indexed from 1 to \(N\). You need to process \(Q\) queries on this array. There are two types of queries:

  • Type 1: "1 i v" - Update the value at index \(i\) of the array to \(v\).
  • Type 2: "2 l r" - Compute the sum of the subarray from index \(l\) to \(r\) (both inclusive). In other words, compute \(\sum_{i=l}^{r} a_i\).

The input is given via standard input and the output should be printed to standard output. For every query of type 2, output the result in a new line.

inputFormat

The input consists of the following:

  1. The first line contains two integers \(N\) and \(Q\), where \(N\) is the number of elements in the array and \(Q\) is the number of queries.
  2. The second line contains \(N\) space-separated integers representing the initial array \(a_1, a_2, \ldots, a_N\).
  3. The next \(Q\) lines each contain a query in one of the following formats:
    • "1 i v" indicating that the value at index \(i\) should be updated to \(v\).
    • "2 l r" indicating that the sum of the subarray from index \(l\) to \(r\) should be computed.

outputFormat

For each query of type 2, print the computed sum on a new line.

## sample
5 4
1 2 3 4 5
2 1 3
1 2 10
2 2 4
2 1 5
6

17 23

</p>