#K58702. Array Operations Processor
Array Operations Processor
Array Operations Processor
You are given an array of n integers and q operations to perform on the array. There are three types of operations:
- Operation 1: Reverse the subarray between indices \(l\) and \(r\) (inclusive).
- Operation 2: Increment every element in the subarray from index \(l\) to \(r\) (inclusive) by 1.
- Operation 3: Compute the sum of the subarray from index \(l\) to \(r\) (inclusive) and output the result.
Indices are 0-based. You are required to process each operation in the order given. For each operation of the third type, output the computed sum on a new line.
Note: The modifications from the first two operations affect subsequent operations.
inputFormat
The input is read from stdin and has the following format:
- The first line contains two integers \(n\) and \(q\), where \(n\) is the number of elements in the array and \(q\) is the number of operations.
- The second line contains \(n\) space-separated integers representing the array.
- The next \(q\) lines each contain three integers: op l r, where op is the type of operation (1 for reverse, 2 for increment, 3 for subarray sum), and \(l\) and \(r\) are the starting and ending indices (inclusive) of the subarray.
outputFormat
For each operation of type 3, output the sum of the specified subarray on a separate line to stdout.
## sample5 4
1 2 3 4 5
2 1 3
3 0 4
1 0 2
3 0 2
18
8
</p>