Under construction

Still being built. Things may change

Masking Tape

Interview

Time limit2sMemory limit2048 MB

Summary
Process paint and tape operations on a grid of 2x2 blocks, then print each cell's color after all tape is removed, where a cell keeps the color it had when first covered.
Level

Medium4 of 10

Topics
Array, Simulation, Implementation
Solved
No attempts yet

Problem

JOI is playing with paper and masking tape, coloring the paper.

The paper is a rectangle with a grid of HH rows and WW columns. The cell in row ii (counting from the top) and column jj (counting from the left) is called cell (i,j)(i, j).

Each cell has one color. Colors are integers. At the start, every cell has color 00.

JOI performs QQ operations with this paper and masking tape. The kk-th operation (1≤k≤Q1 \le k \le Q) depends on the integer qkq_k as follows.

  • If qk=1q_k = 1, the operation is given by integers xk,yk,ckx_k, y_k, c_k. For each of the cells (xk,yk)(x_k, y_k), (xk+1,yk)(x_k + 1, y_k), (xk,yk+1)(x_k, y_k + 1), and (xk+1,yk+1)(x_k + 1, y_k + 1), if the cell is not covered by masking tape, change its color to ckc_k. If the cell is covered by masking tape, do nothing to it.
  • If qk=2q_k = 2, the operation is given by integers xk,ykx_k, y_k. Cover the cells (xk,yk)(x_k, y_k), (xk+1,yk)(x_k + 1, y_k), (xk,yk+1)(x_k, y_k + 1), and (xk+1,yk+1)(x_k + 1, y_k + 1) with masking tape.

After all QQ operations, remove all the masking tape. When the tape is removed from a cell, the cell's color becomes the color it had just before it was covered.

Find the final color of every cell on the paper.

Input

The input is given in the following format.

H W Q
(Query 1)
(Query 2)
:
(Query Q)

Each (Query k)(\text{Query } k) (1≤k≤Q1 \le k \le Q) is a line of space-separated integers. The first integer is qkq_k.

  • If qk=1q_k = 1, the line contains three more integers xk,yk,ckx_k, y_k, c_k.
  • If qk=2q_k = 2, the line contains two more integers xk,ykx_k, y_k.

Output

Print the final color of every cell in HH lines. The ii-th line contains WW space-separated integers, where the jj-th integer is the color of cell (i,j)(i, j).

Constraints

  • 2≤H≤5002 \le H \le 500.
  • 2≤W≤5002 \le W \le 500.
  • 1≤Q≤200 0001 \le Q \le 200\,000.
  • qkq_k is either 11 or 22 (1≤k≤Q1 \le k \le Q).
  • If qk=1q_k = 1, then 1≤xk≤H−11 \le x_k \le H - 1, 1≤yk≤W−11 \le y_k \le W - 1, and 1≤ck≤1091 \le c_k \le 10^9 (1≤k≤Q1 \le k \le Q).
  • If qk=2q_k = 2, then 1≤xk≤H−11 \le x_k \le H - 1 and 1≤yk≤W−11 \le y_k \le W - 1 (1≤k≤Q1 \le k \le Q).
  • All input values are integers.

Examples3

  1. Example 1

    Input
    5 5 4
    1 2 2 1
    2 1 2
    2 3 3
    1 1 3 5
    
    Expected output
    0 0 0 5 0
    0 1 1 5 0
    0 1 1 0 0
    0 0 0 0 0
    0 0 0 0 0
    
  2. Example 2

    Input
    5 5 3
    1 1 1 2
    1 3 3 3
    1 2 4 2
    
    Expected output
    2 2 0 0 0
    2 2 0 2 2
    0 0 3 2 2
    0 0 3 3 0
    0 0 0 0 0
    
  3. Example 3

    Input
    10 10 10
    2 5 7
    2 5 6
    1 5 6 1
    1 9 2 1
    2 1 1
    1 2 4 2
    2 3 2
    1 2 2 3
    1 9 9 2
    1 8 8 1
    
    Expected output
    0 0 0 0 0 0 0 0 0 0
    0 0 3 2 2 0 0 0 0 0
    0 0 0 2 2 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 1 1 0
    0 1 1 0 0 0 0 1 1 2
    0 1 1 0 0 0 0 0 2 2