#C10417. Partial Array Reversal
Partial Array Reversal
Partial Array Reversal
Given an array of integers and four indices k1, k2, k3, and k4, your task is to reverse two subarrays of the given array. First, reverse the subarray that starts at index k1 and ends at index k2 (both inclusive). Then, reverse the subarray that starts at index k3 and ends at index k4 (both inclusive).
Note: The indices are zero-indexed. You are guaranteed that the indices define valid subarrays in the given array.
The reversal process can be mathematically described using the following formula for a subarray reversal:
For a subarray A starting at index l and ending at index r, the new index i' of an element originally at index i is given by:
[ i' = l + (r - i)]
Apply this operation twice on the original array with the two given pairs.
inputFormat
The input is given via standard input (stdin) and consists of three lines:
- The first line contains a single integer n, the number of elements in the array.
- The second line contains n space-separated integers representing the array elements.
- The third line contains four space-separated integers: k1, k2, k3, and k4.
outputFormat
Output the modified array to standard output (stdout) in a single line with the array elements separated by a space.
## sample7
1 2 3 4 5 6 7
1 3 4 6
1 4 3 2 7 6 5