#C1208. Sequence Query and Update

    ID: 41467 Type: Default 1000ms 256MiB

Sequence Query and Update

Sequence Query and Update

You are given a sequence consisting of n integers. Your task is to perform a series of operations on this sequence. There are two types of operations:

  • Update: Update the i-th element of the sequence to a new value x.
  • Query: Calculate the sum of a subarray from index l to r (both inclusive). In mathematical terms, compute \(\sum_{i=l}^{r}a_i\).

All indices are 1-indexed. The operations will be provided in a mixed order. For each query operation, output the result on a new line.

inputFormat

The input is given from stdin in the following format:

n q
a1 a2 ... an
op1 arg1 arg2
op2 arg1 arg2
... 
opq [arguments]
  • The first line contains two integers n (the number of elements in the sequence) and q (the number of operations).
  • The second line contains n integers representing the initial sequence.
  • The next q lines each represent an operation. Each operation is given in one of the following two formats:
    • Q l r – a query operation asking for the sum of the subarray from index l to r.
    • U i x – an update operation to set the i-th element to x.

outputFormat

For each query operation (Q l r), output the sum of the subarray from l to r on a single line.

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

14

</p>