City Lights Queries
View as PDFYou are looking at a square nighttime skyline represented as an grid.
Each cell is one window: a lit window is marked with
*, and a dark window is marked
with ..
You must answer queries. Each query gives the top-left corner
and the bottom-right corner
of a rectangle, and asks
how many lit windows are inside that rectangle.
Input
The first line contains two integers and
.
The next lines each contain a string of length
describing the grid.
Each of the next lines contains four integers
describing
an inclusive query rectangle.
Here, stands for row and
stands for column, so each query is given as
row column row column.
Rows and columns are numbered from to
, and the first pair
is the top-left corner while the second pair
is the
bottom-right corner.
Output
For each query, output a single integer: the number of lit windows inside the requested rectangle.
Constraints
Example 1
Input
4 3
.*..
**..
..*.
***.
1 1 2 2
2 2 4 4
3 3 3 3
Output
3
4
1
Example 2
Input
5 3
*....
.*...
..*..
...*.
....*
1 1 5 5
2 1 4 3
1 5 5 5
Output
5
2
1
Comments