Masking Tape
InterviewTime limit2sMemory limit2048 MB
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 rows and columns. The cell in row (counting from the top) and column (counting from the left) is called cell .
Each cell has one color. Colors are integers. At the start, every cell has color .
JOI performs operations with this paper and masking tape. The -th operation () depends on the integer as follows.
- If , the operation is given by integers . For each of the cells , , , and , if the cell is not covered by masking tape, change its color to . If the cell is covered by masking tape, do nothing to it.
- If , the operation is given by integers . Cover the cells , , , and with masking tape.
After all 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 () is a line of space-separated integers. The first integer is .
- If , the line contains three more integers .
- If , the line contains two more integers .
Output
Print the final color of every cell in lines. The -th line contains space-separated integers, where the -th integer is the color of cell .
Constraints
- .
- .
- .
- is either or ().
- If , then , , and ().
- If , then and ().
- All input values are integers.