#C1542. Delivery Matrix Operations
Delivery Matrix Operations
Delivery Matrix Operations
You are given an N × N matrix that represents a delivery schedule. Each cell of the matrix is initialized by the formula
$M_{ij} = ((i \cdot A) + (j \cdot B)) \mod C$,
where i and j are the row and column indices (starting from 1). You are then required to perform a sequence of operations on the matrix. The operations are:
- update r c v: Update the cell at row r and column c to value v.
- add r1 c1 r2 c2: Add the value at cell (r1,c1) to the cell (r2,c2).
- swap r1 c1 r2 c2: Swap the values between the cells (r1, c1) and (r2, c2).
- rowsum r: Output the sum of all values in the r-th row.
- colsum c: Output the sum of all values in the c-th column.
- submatrix D E F G: Output the sum of all values in the submatrix defined by the rows D through E and columns F through G.
You are to process Q operations in the order they are given. For the operations that require output (rowsum
, colsum
, and submatrix
), print the result on a new line.
inputFormat
The first line of input consists of four integers N, A, B, and C.
The second line contains an integer Q, the number of operations.
Each of the following Q lines contains an operation in one of the following formats:
update r c v
add r1 c1 r2 c2
swap r1 c1 r2 c2
rowsum r
colsum c
submatrix D E F G
Note that the indices are 1-indexed.
outputFormat
For each operation that produces an output (rowsum
, colsum
, submatrix
), output the computed value on a separate line.
2 3 6 12
6
update 1 1 9
add 1 1 2 2
rowsum 1
colsum 1
swap 1 1 2 2
submatrix 1 2 1 2
19
20
53
</p>