#B3964. Visible Balloons on the Grassland
Visible Balloons on the Grassland
Visible Balloons on the Grassland
You are given a large grassland which is divided into $n$ rows and $m$ columns. In the sky above the grassland, there are $k$ balloons. The i-th balloon is positioned above row $x_i$ and column $y_i$ with a height of $h_i$ from the ground, and its color is given by $c_i$.
From any position on the grassland, when you look upward, you will only see the balloon that is directly overhead with the smallest height (i.e. the one closest to the ground). If there is no balloon above that position, the visible color is 0.
Your task is to determine the color of the balloon visible when looking upward from every position on the grassland. If no balloon is present above a particular position, output 0 for that position.
inputFormat
The input begins with a line containing three integers $n$, $m$, and $k$ ($1\le n,m$, and $k\ge 0$). Each of the next $k$ lines contains four integers $x_i$, $y_i$, $h_i$, and $c_i$ representing that there is a balloon above row $x_i$, column $y_i$ with height $h_i$ and color $c_i$.
Note: The rows and columns are 1-indexed.
outputFormat
Output $n$ lines, each containing $m$ integers. The j-th integer on the i-th line should be the color of the balloon visible from the cell at row $i$ and column $j$ when looking upward. If there is no balloon in that position, output 0 for that cell.
sample
3 3 2
1 1 5 1
2 2 3 2
1 0 0
0 2 0
0 0 0
</p>