Find the Hole

0

0 votes
Easy-Medium
Problem

Ross has the map of Infinity-land. Infinity-land is divided into large number of regions. Some of those regions may contain the holes denoted by ‘O’ while some may contain settlements denoted by ‘X’. Each region is denoted by the Cartesian point (x,y) as shown below
block
Given the ‘m’ queries of Coordinates of two regions, find the number of holes in the region bounded by those two coordinates.
Input Format:
First line contains two integer n, m where n is the no. of rows and columns and m represents no. of queries. Subsequent lines contain the region configuration containing ‘O’ and ‘X’ Then the subsequent m lines contains four integers where first two integers denote the coordinate of one region and next two represents the coordinate of other region
Output Format:
No. of holes in the bounded region
Constraints:
0 < n < 501
0 < m <=n
0 < Coordinates < n+1

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

From First query,
Case1
Thus from the given region, the no. of regions with holes are 2.

Editor Image

?