#C4370. Reverse Subarrays

    ID: 47901 Type: Default 1000ms 256MiB

Reverse Subarrays

Reverse Subarrays

You are given an array of n integers and q queries. For each query, specified by two integers L and R (using 1-indexed positions), you need to reverse the subarray between positions L and R (inclusive). The operations are performed sequentially; that is, each reversal affects the current state of the array. The reversal operation for a subarray can be expressed as:

$$A[L \ldots R] = \text{reverse}(A[L \ldots R])$$

Your task is to print the final state of the array after performing all the queries.

inputFormat

The input is given via stdin with the following format:

  • The first line contains an integer n, the number of elements in the array.
  • The second line contains n space-separated integers, representing the elements of the array.
  • The third line contains an integer q, the number of queries.
  • Each of the next q lines contains two space-separated integers: L and R.

outputFormat

Output the final state of the array as a single line of space-separated integers to stdout.

## sample
5
1 2 3 4 5
3
1 3
2 4
1 5
5 2 1 4 3

</p>