#K82912. Drawing Rectangles on a Canvas
Drawing Rectangles on a Canvas
Drawing Rectangles on a Canvas
You are given a canvas represented as an M x N grid. Initially, all cells in the grid have a value of 0. You are also given R rectangles, each specified by four integers r1, c1, r2, c2 that represent the top-left and bottom-right coordinates of the rectangle (inclusive). For each rectangle, add 1 to every cell within the specified rectangle area.
Your task is to compute the final state of the canvas after drawing all the rectangles. The cell values should reflect the number of times that cell was covered by any of the rectangles.
Note: The grid uses 0-based indexing.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
The first line contains three integers M, N, and R, where M is the number of rows, N is the number of columns, and R is the number of rectangles.
The following R lines each contain four integers: r1 c1 r2 c2, describing a rectangle's top-left and bottom-right coordinates.
outputFormat
Output the final state of the canvas to standard output (stdout). Each of the M lines should contain N space-separated integers representing the grid rows after all rectangles have been drawn.
## sample5 5 3
1 1 3 3
0 0 2 2
2 2 4 4
1 1 1 0 0
1 2 2 1 0
1 2 3 2 1
0 1 2 2 1
0 0 1 1 1
</p>