#C1011. Reverse a Subarray Segment

    ID: 39279 Type: Default 1000ms 256MiB

Reverse a Subarray Segment

Reverse a Subarray Segment

Given an array of n integers and two indices l and r (1-indexed), your task is to reverse the subarray from position l to r. Formally, if the array is represented as \(a_1, a_2, \ldots, a_n\), you need to transform it into:

[ a_1, \ldots, a_{l-1}, a_r, a_{r-1}, \ldots, a_l, a_{r+1}, \ldots, a_n ]

and then output the modified array. Note that if \(l = r\), the array remains unchanged.

inputFormat

The input consists of three lines:

  • The first line contains a single integer \(n\) which denotes the size of the array.
  • The second line contains \(n\) space-separated integers representing the elements of the array.
  • The third line contains two space-separated integers \(l\) and \(r\) (1-indexed) which denote the start and end indices of the segment to be reversed.

outputFormat

Output the modified array after reversing the segment. The elements must be printed in a single line separated by spaces.

## sample
10
1 2 3 4 5 6 7 8 9 10
3 7
1 2 7 6 5 4 3 8 9 10