#K37232. Taco Game Operations
Taco Game Operations
Taco Game Operations
You are given a sequence of n integers followed by q operations. In each operation, you are given three integers \(L\), \(R\), and \(K\). The operation is defined as follows:
- Reverse the subarray of the sequence from index \(L\) to \(R\) (inclusive, using 1-indexing).
- Calculate the sum of the first \(K\) elements and the last \(K\) elements of the updated sequence.
Formally, after performing the reversal, if the updated sequence is \(a_1, a_2, \ldots, a_n\), then you should output:
\[ S = \left( \sum_{i=1}^{K} a_i \right) + \left( \sum_{i=n-K+1}^{n} a_i \right)\]Operations are executed sequentially, meaning each reversal persists for subsequent operations. It is guaranteed that \(1 \le L \le R \le n\) and \(K \le n\).
Print the result for each operation on a separate line.
inputFormat
The input is given from standard input (stdin) as follows:
- An integer \(n\) denoting the number of elements in the sequence.
- A line with \(n\) space-separated integers representing the sequence.
- An integer \(q\) representing the number of operations.
- Then \(q\) lines follow, each containing three space-separated integers \(L\), \(R\), and \(K\) describing an operation.
outputFormat
For each operation, output a single line with the computed sum after performing the operation.
## sample6
1 2 3 4 5 6
2
1 4 2
2 5 3
18
21
</p>