#P9117. Grid Coloring Game
Grid Coloring Game
Grid Coloring Game
You are given a grid with \( n \) rows and \( m \) columns. Initially, all cells are white (denoted by 0). At the beginning, each row (on its left) and each column (on its top) has a colored brush. When a brush is clicked, it paints the entire row (if it is a row brush) or entire column (if it is a column brush) to the right or below of the brush with a specified color. Note that the operation will override any previous colors in that row or column completely.
You will be given \( q \) operations. Each operation is described by three integers \( opt_i, x_i, c_i \):
- If \( opt_i = 0 \), paint the \( x_i \)-th row with color \( c_i \).
- If \( opt_i = 1 \), paint the \( x_i \)-th column with color \( c_i \).
After executing all operations, output the final color of each cell in the grid. Note that the rows and columns are 1-indexed.
inputFormat
The first line contains two integers \( n \) and \( m \) representing the number of rows and columns of the grid respectively.
The second line contains an integer \( q \) representing the number of operations.
The following \( q \) lines each contain three integers \( opt_i \), \( x_i \), and \( c_i \) describing an operation.
outputFormat
Output \( n \) lines, each with \( m \) integers, where the \( j \)-th integer in the \( i \)-th line is the final color of the cell at row \( i \) and column \( j \). Numbers in each line should be separated by a single space.
sample
3 3
2
0 1 1
1 3 2
1 1 2
0 0 2
0 0 2
</p>