#K35742. Assemble Widget using Rectangular Components

    ID: 25599 Type: Default 1000ms 256MiB

Assemble Widget using Rectangular Components

Assemble Widget using Rectangular Components

You are given the dimensions of a widget and a series of operations that place rectangular components on the widget. The widget is represented as a 2D grid with widget_height rows and widget_width columns. Each operation is described by four integers \(h\), \(w\), \(r\), and \(c\), which represent the height, width, and the starting row and column (0-indexed) of a rectangular component.

The components are applied in the order they are given. The first operation places a component with id 1, the second with id 2, and so on. When placing a component, each cell in the corresponding subgrid of size \(h \times w\) is filled with the component's id. If no component covers a cell, it remains 0.

Your task is to assemble the widget based on the provided operations and output the resulting grid.

inputFormat

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

  1. A line with two integers: widget_height and widget_width.
  2. A line with an integer n representing the number of operations.
  3. n lines, each containing four integers: h, w, r, and c.

outputFormat

Output the assembled widget grid to standard output (stdout). Each of the widget_height lines should contain widget_width integers separated by spaces.

## sample
3 5
3
2 3 0 0
2 2 1 3
1 4 2 1
1 1 1 0 0

1 1 1 2 2 0 3 3 3 3

</p>