#K66417. Sequence Queries

    ID: 32416 Type: Default 1000ms 256MiB

Sequence Queries

Sequence Queries

You are given a sequence of n integers and q queries. The queries are of two types:

  • Update Query (Type 1): Update the element at position x (1-indexed) to a new value y. In mathematical notation, if the original sequence is \(A = [a_1, a_2, \dots, a_n]\), then after an update at index \(x\), \(a_x = y\).
  • Range Sum Query (Type 2): Calculate the sum of the elements in the subarray from index l to index r (inclusive). Formally, compute \(\sum_{i=l}^{r} a_i\).

Process all queries in the order given. For each range sum query (Type 2), output the computed sum on a separate line.

inputFormat

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

  1. The first line contains two integers n and q, where n is the number of elements in the sequence and q is the number of queries.
  2. The second line contains n space-separated integers representing the initial sequence.
  3. The next q lines each represent a query in one of the following formats:
    • For an update query: 1 x y (update the element at index x to y).
    • For a range sum query: 2 l r (calculate the sum from index l to r inclusive).

outputFormat

For each range sum query (Type 2), output a single integer in a separate line, which is the sum of the elements in the specified range.

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

13 19

</p>