#P5350. Sequence Operations Simulator
Sequence Operations Simulator
Sequence Operations Simulator
You are given a sequence \(a_1, a_2, \dots, a_n\) and you need to perform \(m\) operations on it. The operations are as follows:
- 1 l r: Compute the sum \(a_l + a_{l+1} + \dots + a_r\).
- 2 l r val: Assign the value \(val\) to each element in the range \(a_l, a_{l+1}, \dots, a_r\), i.e. set \(a_i = val\) for all \(l \le i \le r\).
- 3 l r val: Add \(val\) to each element in the range, i.e. update \(a_i = a_i + val\) for all \(l \le i \le r\).
- 4 l_1 r_1 l_2 r_2: Copy the subsequence \(a_{l_1}, a_{l_1+1}, \dots, a_{r_1}\) to the segment \(a_{l_2}, a_{l_2+1}, \dots, a_{r_2}\). It is guaranteed that \(r_1-l_1 = r_2-l_2\).
- 5 l_1 r_1 l_2 r_2: Swap the subsequences \(a_{l_1}, a_{l_1+1}, \dots, a_{r_1}\) and \(a_{l_2}, a_{l_2+1}, \dots, a_{r_2}\). It is guaranteed that both segments have the same length.
- 6 l r: Reverse the segment \(a_l, a_{l+1}, \dots, a_r\).
For each operation of type 1, output the result on a separate line.
inputFormat
The first line contains two integers \(n\) and \(m\) — the number of elements in the sequence and the number of operations to perform.
The second line contains \(n\) integers representing the initial sequence \(a_1, a_2, \dots, a_n\).
The following \(m\) lines each describe an operation in one of the formats defined above.
Note: The array is 1-indexed.
outputFormat
For each operation of type 1, output a single line containing the sum of the specified segment.
sample
5 4
1 2 3 4 5
1 2 4
3 1 3 10
1 1 5
6 2 4
9
45
</p>