#P3483. Monument Protection in Bytau
Monument Protection in Bytau
Monument Protection in Bytau
In Bytau, the capital of Byteotia, the city is laid out on a perfect grid of streets running north–south and east–west. Intersections are exactly 1 km apart and every intersection hosts a historic monument. The City Council plans various projects to place two main fire stations. Each monument is protected by the station to which its Manhattan distance is smaller; if the distances are equal, then the monument is protected by both stations.
Given the dimensions of the city and the positions of the two fire stations for several projects, your task is to determine for each project the number of monuments that are protected by only the first station, by only the second station, and by both stations, respectively.
The Manhattan distance between two points \((r_1, c_1)\) and \((r_2, c_2)\) is given by \( |r_1 - r_2| + |c_1 - c_2| \).
inputFormat
The input consists of multiple lines:
- The first line contains two integers \(R\) and \(C\) (\(1 \leq R, C \leq 100\)) representing the number of rows and columns of intersections in the city.
- The second line contains an integer \(Q\) (\(1 \leq Q \leq 100\)) representing the number of projects.
- Each of the next \(Q\) lines contains four integers: \(r_1\), \(c_1\), \(r_2\), and \(c_2\) (with \(1 \leq r_1, r_2 \leq R\) and \(1 \leq c_1, c_2 \leq C\)), which represent the positions of the first and second fire stations, respectively. The positions are given in 1-indexed row and column coordinates.
outputFormat
For each project, output three integers separated by spaces: the number of monuments protected by the first station only, the number protected by the second station only, and the number protected by both stations.
sample
5 5
3
1 1 5 5
3 3 3 3
1 3 5 3
10 9 6
0 0 25
10 10 5
</p>