#P9117. [春季测试 2023] 涂色游戏

[春季测试 2023] 涂色游戏

Problem Description

One day, when Xiao D was browsing Moments, he saw a video of a game.

The game is called Coloring Game. In the video, the game screen is a grid with nn rows and mm columns. At the beginning, every cell is white (represented by the number 00). There is a colored brush on the left side of each row and above each column. After the player clicks a brush, it will paint the entire row (or entire column) to its right (or below) into the same color. The original colors of the cells in that row (or column) will all be overwritten by the new color.

The situation shown in the figure below can be obtained by first painting the first column red, and then painting the first row blue. If we now choose to paint the third column green, then all cells inside the green boxes in the figure will become green.

Xiao D wants to use his own program to play the game in the video. During programming, he encountered some difficulties in implementing the coloring logic, so he asked you for help and hopes you can finish the code for the coloring logic part.

First, Xiao D will give you the number of rows and columns of the grid n,mn, m, and then give qq operations. Each operation is represented by three integers opti,xi,ciopt_i, x_i, c_i:

  • If opti=0opt_i = 0, this operation paints row xix_i into color cic_i.
  • If opti=1opt_i = 1, this operation paints column xix_i into color cic_i.

After all coloring operations are finished, you need to output the color at every position in the grid.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT, indicating the number of test cases.

Then there are TT test cases. Each test case is in the following format:

The first line contains three integers n,m,qn, m, q, representing the number of rows and columns of the coloring board, and the number of coloring operations Xiao D performs.

The next qq lines each contain three integers opti,xi,ciopt_i, x_i, c_i, representing one operation.

Output Format

For each test case, output nn lines, each containing mm integers separated by single spaces.

The jj-th integer in the ii-th line indicates the color of the cell at row ii and column jj after all coloring is completed.

2
5 5 9
1 5 1
0 4 0
1 4 1
0 3 0
1 3 1
0 2 0
1 2 1
0 1 0
1 1 1
3 3 3
0 1 2
0 3 1
1 1 3
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
3 2 2
3 0 0
3 1 1

Hint

[Sample 1 Explanation]

Note that when a cell is not painted, its color is white, represented by the number 00.

[Sample 2]

See paint/paint2.in and paint/paint2.ans in the contestant directory.

[Constraints]

For all data, it is guaranteed that:

  • 1T101 \leq T \leq 10, 1n,m1051 \leq n, m \leq 10^5, 0q1050 \leq q \leq 10^5, 0ci1090 \leq c_i \leq 10^9.
  • If opti=0opt_i = 0, then 1xin1 \leq x_i \leq n; if opti=1opt_i = 1, then 1xim1 \leq x_i \leq m.
  • In a single test, the sum of nmn \cdot m over all test cases does not exceed 10610^6, and the sum of qq does not exceed 10610^6.
Test Point nn \le mm \le qq \le Property A Property B
1 11 11 00
2 11
3 1010 2020
4 10510^5 ×
5
6 ×
7 1010 2020
8 5050 100100
9 ×
10 10001000 20002000 ×
11 ×
12
13 10510^5
14
15 10510^5
16
17 ×
18
19 ×
20

Special Property A: It is guaranteed that, over all test cases in a test point, the sum of qmax(n,m)q \cdot \max(n, m) does not exceed 10710^7.

Special Property B: It is guaranteed that opti=1opt_i = 1.

[Reminder]

There are thousands of lines of data; clearing the first one is the most important. If you do not clear for multiple test cases, you will get zero points, and tears will fall in two lines.

Translated by ChatGPT 5