#P8659. Array Operations with Range Updates and Range Assignments
Array Operations with Range Updates and Range Assignments
Array Operations with Range Updates and Range Assignments
You are given an array \( A[1\ldots n] \) of length \( n \). You need to process \( m \) operations on this array. The operations are of three types:
- Operation 1:
1 L R d
. For every index \( i \) with \( L \le i \le R \), perform \( A[i] \leftarrow A[i] + d \). - Operation 2:
2 L_1 R_1 L_2 R_2
. Copy the segment \( A[L_2\ldots R_2] \) to \( A[L_1\ldots R_1] \). It is guaranteed that \( R_1 - L_1 = R_2 - L_2 \). In other words, let \( k = R_2 - L_2 \); for every \( i \) from \( 0 \) to \( k \), perform \( A[L_1+i] \leftarrow A[L_2+i] \) (using a temporary buffer if needed). - Operation 3:
3 L R
. Output the sum \( \sum_{i=L}^{R} A[i] \).
All formulas are presented in \( \LaTeX \) format. Your task is to implement these operations and answer the sum queries.
inputFormat
The first line contains two integers \( n \) and \( m \), denoting the length of the array and the number of operations.
The second line contains \( n \) integers, representing the initial values of \( A[1\ldots n] \).
The following \( m \) lines each represent an operation in one of the following formats:
1 L R d
2 L1 R1 L2 R2
3 L R
outputFormat
For each operation of type 3, output a single line containing the sum of \( A[L] \) to \( A[R] \) after performing all previous operations.
sample
5 5
1 2 3 4 5
3 1 5
1 2 4 3
3 1 5
2 1 3 3 5
3 1 5
15
24
30
</p>