#K59587. Paint Enclosures

    ID: 30897 Type: Default 1000ms 256MiB

Paint Enclosures

Paint Enclosures

You are given an m-by-n grid initially filled with the color "white". You need to perform a series of painting operations on this grid. Each operation is described by five values:

\( r_1 \), \( c_1 \), \( r_2 \), \( c_2 \) and color, where \( (r_1, c_1) \) represents the top-left cell and \( (r_2, c_2) \) the bottom-right cell of the sub-grid to paint (using 0-indexing).

For each painting operation, update every cell in the specified rectangular region with the given color. Operations are performed in the order they are given, meaning that a later operation may override the color of cells painted by an earlier one.

Your task is to compute the final state of the grid and output it row by row.

inputFormat

The input is read from standard input (stdin) and has the following format:

 m n
 q
 r1 c1 r2 c2 color
 r1 c1 r2 c2 color
 ... (q lines in total)

Where:

  • m and n are the number of rows and columns in the grid, respectively.
  • q is the number of painting operations.
  • Each subsequent line contains an operation with four integers r1, c1, r2, and c2 followed by a string color.
  • It is guaranteed that \(0 \le r_1 \le r_2 < m\) and \(0 \le c_1 \le c_2 < n\).

outputFormat

The output is written to standard output (stdout). Print the final grid state where each row is printed on a new line and the colors in the row are separated by a single space.

## sample
2 2
1
0 0 1 1 blue
blue blue

blue blue

</p>