#K63627. Array Update and Query

    ID: 31796 Type: Default 1000ms 256MiB

Array Update and Query

Array Update and Query

Problem Description:

You are given an array of integers of size \(N\). You need to perform \(M\) operations on this array. There are two types of operations:

  • Update Operation: U i v which updates the element at index \(i\) to \(v\), i.e. \(A[i] = v\).
  • Sum Query: S l r which requires you to compute the sum \(\sum_{i=l}^{r} A[i]\) for the subarray from index \(l\) to \(r\) (inclusive).

Note: Array indices are zero-based. The input is read from standard input and the result of each sum query should be printed on a new line to standard output.

inputFormat

Input Format:

The first line contains two integers \(N\) and \(M\), where \(N\) is the number of elements in the array and \(M\) is the number of operations.

The second line contains \(N\) space-separated integers representing the initial array elements.

The following \(M\) lines each contain an operation in one of the following two formats:

  • U i v representing an update operation (set \(A[i] = v\)).
  • S l r representing a sum query (compute \(\sum_{i=l}^{r} A[i]\)).

outputFormat

Output Format:

For each sum query operation (S l r), output the resulting sum on a new line.

## sample
5 4
2 4 1 5 3
S 0 2
U 1 7
S 0 3
S 2 4
7

15 9

</p>