#K86227. Average Brightness Query
Average Brightness Query
Average Brightness Query
You are given a grayscale image represented as a 2D array of integers. Each integer in the array represents the brightness of a pixel. You need to process a series of queries to calculate the average brightness of a specified rectangular region of the image. For each query, the average brightness is computed using floor division:
\( \text{Average} = \left\lfloor \frac{\sum_{(i,j) \in R} image[i][j]}{\text{number of pixels in } R} \right\rfloor \)
The coordinates for the queries are provided in 1-indexed format.
inputFormat
The input is given from standard input (stdin) as follows:
- The first line contains three space-separated integers \(n\), \(m\), and \(q\) where \(n\) is the number of rows, \(m\) is the number of columns of the image, and \(q\) is the number of queries.
- The next \(n\) lines each contain \(m\) space-separated integers representing the brightness values of the image.
- The following \(q\) lines each contain four space-separated integers \(x_1\), \(y_1\), \(x_2\), and \(y_2\) describing a query rectangle, where \((x_1, y_1)\) is the top-left corner and \((x_2, y_2)\) is the bottom-right corner (inclusive).
outputFormat
For each query, output a single line containing one integer: the average brightness (using floor division) of the specified rectangular region.
## sample4 4 2
30 50 70 10
20 80 90 50
40 60 100 30
70 10 20 80
1 1 2 2
3 2 4 4
45
50
</p>