#P6707. [COCI 2010/2011 #7] UPIT

[COCI 2010/2011 #7] UPIT

Background

Mirko is tired of implementing different data structures for different tasks. So, he decided to write one ultimate data structure to handle his favorite sequence of numbers.

Come and help him!

Mirko will give you his sequence, as well as a series of operations you must perform. Each query either asks for information about the sequence or modifies the existing sequence. All possible operation types are listed below.

Query type Description Example
1 A B X Change all elements in [A,B][A,B] to XX (9,8,7,6,5,4,3,2,1)(9, 8, 7, 6, 5, 4, 3, 2, 1)\to 11 33 55 00 \to (9,8,0,0,0,4,3,2,1)(9, 8, 0, 0, 0, 4, 3, 2, 1)
2 A B X Increase all elements in [A,B][A,B] by a value: position A+kA+k increases by (k+1)×X(k+1) \times X (9,8,7,6,5,4,3,2,1)(9, 8, 7, 6, 5, 4, 3, 2, 1)\to 22 33 55 22 (9,8,9,10,11,4,3,2,1)\to (9, 8, 9, 10, 11, 4, 3, 2, 1)
3 C X Insert a number with value XX before the original position CC (9,8,7,6,5,4,3,2,1)(9, 8, 7, 6, 5, 4, 3, 2, 1) \to 33 44 100100 \to (9,8,7,100,6,5,4,3,2,1)(9, 8, 7, 100, 6, 5, 4, 3, 2, 1)
4 A B Query the sum of values in [A,B][A,B] (2,18,7,6,1,4,7,7,2)(2, 18, 7, 6, 1, 4, 7, 7, 2) \to 44 66 77 \to result:11result: 11

Problem Description

Given a sequence ff, the following operations are supported.

Let the current length of the sequence be nn.

Query type Description
1 A B X fi=X(AiB)f_i = X (A \le i \le B).
2 A B X fi+=(iA+1)×X(AiB)f_i += (i - A + 1) \times X (A \le i \le B).
3 C X fi+1=fi(Cin)f_{i+1} = f_i (C \le i \le n), fC=Xf_C = X.
4 A B Compute i=ABfi\sum^B_{i=A} f_i.

Input Format

The first line contains two positive integers nn and QQ, representing the initial length of the sequence and the number of operations.

The second line contains nn non-negative integers, representing the initial sequence.

The next QQ lines each contain one query as described above.

Output Format

For each type 44 operation, output one line with the answer.

5 5
1 2 3 4 5
1 5 5 0
4 4 5
4 5 5
2 1 5 1
4 1 5
4
0
25
1 7
100
3 1 17
3 2 27
3 4 37
4 1 1
4 2 2
4 3 3
4 4 4
17
27
100
37

Hint

Constraints

Let the current sequence length be tt.

For 100%100\% of the testdata: 1n,Q1×1051 \le n, Q \le 1 \times 10^5, fi1×105f_i \le 1 \times 10^5, 1X1001 \le X \le 100, 1ABt1 \le A \le B \le t, 1Ct+11 \le C \le t + 1.

Notes

This problem is worth 130130 points in total.

Translated from COCI2010-2011 CONTEST #7 T6 UPIT.

Translated by ChatGPT 5