City Lights Queries
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
2.0s
Python 3
2.0s
Memory limit:
977M
Problem type
You 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.
Rows and columns are numbered from to
.
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