#C8235. Array Operations

    ID: 52195 Type: Default 1000ms 256MiB

Array Operations

Array Operations

You are given an array of integers and are required to perform several operations on it. The operations are defined as follows:

  • SUM l r: Print the sum of the elements between indices l and r (both inclusive) using 1-based indexing. In mathematical terms, compute: \( \sum_{i=l}^{r} a_i \).
  • SWAP x y: Swap the elements at 1-based indices x and y.
  • UPDATE x v: Update the element at the 1-based index x to value v.

You need to process Q operations on the array and for every "SUM" operation, print the result on a new line.

Note: All indices are 1-based.

inputFormat

The input is given via stdin and has the following format:

  1. An integer N denoting the number of elements in the array.
  2. A line with N space-separated integers representing the array elements.
  3. An integer Q representing the number of operations.
  4. Q lines follow, each describing an operation in one of the following formats:
    • SUM l r
    • SWAP x y
    • UPDATE x v

outputFormat

For each SUM operation, output the computed sum on a new line to stdout.

## sample
5
1 2 3 4 5
5
SUM 1 3
SWAP 2 4
SUM 2 5
UPDATE 3 10
SUM 1 3
6

14 15

</p>