#P4433. Box Stone Simulation
Box Stone Simulation
Box Stone Simulation
You are given ( n ) boxes (initially all with 0 stones) and ( q ) operations. There are two types of operations:
1. Operation of type 1: The input is given as 1 L R A B
. For each box with index ( X ) ranging from ( L ) to ( R ), update its stone count to
[
\text{stones}[X] = ((X - L + 1) \times A) \bmod B
]
Note that the operation overwrites the previous stone count in the box.
2. Operation of type 2: The input is given as 2 L R
. For this operation, output the sum of stones in the boxes with indices from ( L ) to ( R ).
inputFormat
The first line contains two integers ( n ) and ( q ), representing the number of boxes and the number of operations, respectively. The following ( q ) lines each describe an operation. An operation is given in one of the following two formats:
- 1 L R A B
: update the boxes from index ( L ) to ( R ) as described above.
- 2 L R
: query the sum of stones in boxes from index ( L ) to ( R ).
outputFormat
For each operation of type 2, output a single line containing the sum of stones in the specified range.
sample
5 5
1 2 4 3 5
2 1 5
1 1 3 2 7
2 2 4
2 3 3
8
14
6
</p>