#K16246. Reverse Subarray Sum

    ID: 24536 Type: Default 1000ms 256MiB

Reverse Subarray Sum

Reverse Subarray Sum

You are given an array of \(N\) integers. For each test case, you must perform the following operation:

  • Reverse the subarray from index \(L\) to \(R\) (0-indexed) if the number of operations \(Q\) is odd.
  • If \(Q\) is even, the array remains unchanged.

After the operation, compute the sum of all elements in the array, i.e. \(\sum_{i=0}^{N-1}{a_i}\).

Note that reversing the subarray an even number of times results in the original subarray order.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  • The first line contains a single integer \(T\), the number of test cases.
  • For each test case, the following lines are provided:
    • The first line contains an integer \(N\) denoting the size of the array.
    • The second line contains \(N\) space-separated integers representing the elements of the array.
    • The third line contains three space-separated integers: \(L\), \(R\), and \(Q\), where \(L\) and \(R\) (0-indexed) specify the range of the subarray to reverse, and \(Q\) is the number of times the reversal operation is performed.

outputFormat

For each test case, output a single line containing the sum of the array after performing the reversal operations.

## sample
3
5
3 8 4 7 6
1 3 2
6
1 2 3 4 5 6
0 5 1
4
2 2 2 2
1 1 5
28

21 8

</p>