#P8659. [蓝桥杯 2017 国 A] 数组操作

[蓝桥杯 2017 国 A] 数组操作

Description

Given an array {A}\{A\} of length nn, indexed from 11 to nn, you need to maintain mm operations.

There are three types of operations, with input formats as follows:

1 L R d: Add dd to all positions in the array with indices from LL to RR. That is, for LiRL \le i \le R, perform A[i]A[i]+dA[i]\leftarrow A[i]+d.

2 L1 R1 L2 R2: Assign the values of positions L2L_2 to R2R_2 to positions L1L_1 to R1R_1. It is guaranteed that R1L1=R2L2R_1-L_1=R_2-L_2.

In other words, first perform BiAL2+iB_i\leftarrow A_{L_2+i} for 0iR2L20 \le i \le R_2-L_2, then perform AL1+iBiA_{L_1+i}\leftarrow B_i for 0iR1L10 \le i \le R_1-L_1, where {B}\{B\} is a temporary array.

3 L R: Query the sum of positions in the array with indices from LL to RR, i.e., compute i=LrAi\sum\limits_{i=L}^{r}A_i.

Input Format

Read input from standard input.

The first line contains an integer Case, indicating the test point ID. When Case is 00, it means this test point is the sample.

The second line contains two integers n,mn,m. It is guaranteed that 1n,m1051 \le n,m \le 10^5.

The third line contains nn integers AiA_i, representing the initial values of the array. It is guaranteed that 0Ai1050 \le A_i \le 10^5.

The next mm lines each describe an operation, in the format shown in the problem description.

For every number mentioned in the operations, it holds that 0d1050 \le d \le 10^5, 1LRn1 \le L \le R \le n, 1L1R1n1 \le L_1 \le R_1 \le n, 1L2R2n1 \le L_2 \le R_2 \le n, and R1L1=R2L2R_1-L_1=R_2-L_2.

Output Format

For each operation of type 33, output one line with one number, representing the sum result.

0
5 6
1 2 3 4 5
2 1 3 3 5
3 3 5
1 2 4 2
3 3 5
2 1 3 3 5
3 1 5
14
18
29

Hint

Test point nn, mm Other constraints
1, 2 103\le10^3 None.
3, 4 105\le10^5 No operation of type 22.
5, 6, 7 nn is even, and all type 22 operations satisfy L1=1L_1=1, R1=n2R_1=\lfloor\frac{n}{2}\rfloor, L2=n2+1L_2=\lfloor\frac{n}{2}\rfloor+1, R2=nR_2=n.
8, 9, 10 None.

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, and 0ai<bi100000 \le a_i<b_i \le 10000.

Translated by ChatGPT 5