loj#P3549. 「COI 2020」Paint
「COI 2020」Paint
Description
We will represent the drawing area of MS Paint as a rectangular grid of unit squares divided into rows and columns. Each square of the grid represents a single pixel that can be colored in one of the different colors. When the user applies the so called bucket tool with color on a pixel which is colored in the color , then all pixels in the monochrome neighborhood of pixel change their color to . Monochrome neighborhood of a pixel is a set of pixels that are reachable by walking from in the four general directions (up, down, left and right) without changing the color of the pixel along the way. Note that the pixel is itself a part of its monochrome neighborhood.
You are given a starting image drawn in MS Paint along with instructions that should be executed in the given order. Each instruction tells you on which pixel should you apply the bucket tool and with what color. Your task is to how the image looks like after all instructions are executed.
Input
The first line contains integers and from the task description.
Each of the next lines contains non-negative integers less than that represent the starting image drawn in MS Paint. More precisely, the -th number in the -th row of the image represents the color of the pixel .
The next line contains an integer from the task description.
The -th of the next lines contains integers , and (, , ), which represent the -th instruction that tells you to use the bucket tool with color on the pixel .
Output
You should output the final state of the image in the same format as it was given in the input.
12 11
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 1 1 1 1
1 1 1 0 0 0 0 0 1 1 1
1 1 0 0 0 0 0 0 0 1 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 2 2 2 0 0 0 1
1 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 2 0 0 0 1 1
0 1 1 0 0 2 0 0 1 1 0
0 0 1 1 0 0 0 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0
2
5 5 3
6 2 4
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 4 4 4 1 1 1 1
1 1 1 4 4 4 4 4 1 1 1
1 1 4 4 4 4 4 4 4 1 1
1 4 4 4 3 3 3 4 4 4 1
1 4 4 4 3 3 3 4 4 4 1
1 4 4 4 3 3 3 4 4 4 1
1 4 4 4 4 4 4 4 4 4 1
1 1 4 4 4 2 4 4 4 1 1
0 1 1 4 4 2 4 4 1 1 0
0 0 1 1 4 4 4 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0
4 4
1 0 1 3
1 3 2 2
3 3 1 2
2 2 1 3
3
1 2 3
3 2 1
4 2 3
1 1 1 3
1 1 2 2
1 1 1 2
3 3 1 3
6 6
1 2 1 2 2 2
3 1 2 1 3 1
3 3 2 3 2 2
2 3 1 3 3 2
3 3 3 3 3 3
2 3 2 2 2 1
4
6 2 2
3 5 2
3 2 3
1 2 3
1 3 1 2 2 2
3 1 3 1 3 1
3 3 3 3 3 3
3 3 1 3 3 3
3 3 3 3 3 3
3 3 3 3 3 1
Scoring
Subtask | Score | Constraints |
---|---|---|
, | ||
, , | ||
, Each pixel will in every moment be colored either in color or color . | ||
, |