#K35972. Array Query Processor

    ID: 25650 Type: Default 1000ms 256MiB

Array Query Processor

Array Query Processor

You are given an array of n integers and m queries. Each query can be one of the following three types:

  • Type 1: "1 a b" -- Swap the elements at indices a and b.
  • Type 2: "2 a b" -- Reverse the subarray from index a to b (inclusive).
  • Type 3: "3 a b" -- Compute and output the sum of the subarray from index a to b (inclusive).

The queries are to be processed sequentially, affecting the array in place. Note that indices are 0-based.

The sum query (type 3) should output the result immediately (or be collected and output in order) on a separate line.

The operations can be summarized using the following notation in LaTeX for a subarray sum query:

\( S = \sum_{i=a}^{b} arr[i] \)

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains two integers n and m, where n is the size of the array and m is the number of queries.
  2. The second line contains n integers separated by spaces representing the array.
  3. The following m lines each contain a query in the format described above.

outputFormat

For each query of type 3, output the sum of the specified subarray on a separate line, writing the output to standard output (stdout).

## sample
5 6
1 2 3 4 5
1 0 4
3 0 4
2 1 3
3 0 4
1 2 3
3 1 3
15

15 9

</p>