#K90937. Process Sequence Operations

    ID: 37863 Type: Default 1000ms 256MiB

Process Sequence Operations

Process Sequence Operations

You are given a sequence of integers and a list of operations to perform on this sequence. The operations can be one of the following:

  • S X Y: Swap the elements at positions \(X\) and \(Y\).
  • A X Y: Add the integer \(Y\) to the element at position \(X\).
  • ? X Y: Compute the sum of the elements from index \(X\) to \(Y\) (inclusive) and output the result.

Note that the indices are 0-indexed. Your task is to process all the operations in the given order and output the results of query operations (the ones starting with ?). If there are no query operations, output nothing.

inputFormat

The first line contains two integers \(n\) and \(m\) where \(n\) is the number of elements in the sequence and \(m\) is the number of operations.

The second line contains \(n\) space-separated integers representing the initial sequence.

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

  • S X Y
  • A X Y
  • ? X Y

outputFormat

For each query operation (? X Y), output the sum of the elements from index \(X\) to \(Y\) on a new line in the order they appear in the input.

## sample
5 4
3 1 4 1 5
S 1 3
A 2 7
? 1 3
? 2 4
13

17

</p>