#K57297. Array Operations Challenge
Array Operations Challenge
Array Operations Challenge
You are given an array of M integers and a sequence of P operations to perform on the array. The operations can be of the following types:
- Type 1: Append an integer Y to the end of the array.
- Type 2: Reverse a sub-array from index I to index J (inclusive). Mathematically, if the sub-array is given by \(A[I \ldots J]\), then after the operation it becomes \(A[J \ldots I]\).
- Type 3: Remove the element at index K from the array.
- Type 4: Output the current state of the array. The array should be printed as a sequence of space-separated integers on one line.
You are required to process the operations in the given order. Whenever a type 4 operation is encountered, output the current state of the array immediately.
Note: The indices provided in the operations are 0-indexed.
inputFormat
The input is given from standard input (stdin) in the following format:
- The first line contains two integers M and P, where M is the initial number of elements in the array and P is the number of operations.
- The second line contains M space-separated integers representing the initial array.
- The next P lines each describe an operation. Each operation begins with an integer representing its type:
- For an operation of type 1, the line contains: 1 Y
- For type 2, the line contains: 2 I J
- For type 3, the line contains: 3 K
- For type 4, the line simply contains: 4
outputFormat
For each type 4 operation, output a line representing the current state of the array as space-separated integers. The output should be produced on standard output (stdout).## sample
3 6
1 2 3
1 4
2 0 2
4
3 1
4
1 5
3 2 1 4
3 1 4
</p>