#K80467. Array Query Processor

    ID: 35537 Type: Default 1000ms 256MiB

Array Query Processor

Array Query Processor

You are given an array \(A\) of length \(n\) and you need to process \(q\) queries on the array. There are two types of queries:

  • Update Query: When a query is of the form 1 i x, update the \(i\)-th element of the array \(A\) to \(x\), i.e. perform \(A[i] = x\).
  • Sum Query: When a query is of the form 2 l r, compute the sum \(\sum_{i=l}^{r} A[i]\) and output the result.

You need to process all the queries in the given order. For the sum queries (type 2), print the result on a new line in the order in which they appear.

Note: The indices are 1-based.

inputFormat

The first line contains two 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 initial elements of the array \(A\). This is followed by \(q\) lines, each line representing a query. A query is given in one of the following forms:

  • 1 i x — Update the element \(A[i]\) to \(x\).
  • 2 l r — Output the sum of the subarray from \(A[l]\) to \(A[r]\), i.e. \(\sum_{i=l}^{r} A[i]\).

outputFormat

For each sum query (type 2), print the result on a new line.

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

21 22

</p>