#K85717. Grid Operations on a 2D Matrix

    ID: 36704 Type: Default 1000ms 256MiB

Grid Operations on a 2D Matrix

Grid Operations on a 2D Matrix

You are given a 2D grid with N rows and M columns, initially filled with zeros. Your task is to perform a series of operations on the grid. There are two types of operations:

  • Update (U): Increase every element in the submatrix defined by the top-left corner (X1, Y1) and bottom-right corner (X2, Y2) by a value V.
  • Query (Q): Compute the sum of all elements in the submatrix defined by (X1, Y1) to (X2, Y2) modulo \(10^9+7\).

The operations will be provided sequentially through the input. You must process each operation in the given order.

Note: The coordinates provided in the operations use 1-indexing.

inputFormat

The input is given via standard input in the following format:

N M
Q
op1
op2
...
opQ

Where:

  • The first line contains two integers N and M representing the number of rows and columns of the grid.
  • The second line contains an integer Q, the number of operations.
  • The following Q lines each describe an operation:
    • Update operation is given as: U X1 Y1 X2 Y2 V
    • Query operation is given as: Q X1 Y1 X2 Y2

outputFormat

For each query operation, output the answer (the sum modulo \(10^9+7\)) on a new line to standard output.

## sample
3 3
2
U 1 1 2 2 5
Q 1 1 3 3
20

</p>