Given a cartesian plane and rectangle on this plane where bottom-left corner has coordinates (x1, y1), the top-right one has coordinates (x2, y2).
Now I need to find the count of those rectangles that have the common area with the rectangle with a bottom-left corner coordinates (x1, y1) and a top-right corner coordinates (x2, y2).
How this can be done in an efficient way?
Their can be many such queries of the form x1 y1 x2 y2 and for given rectangle i need to find count of overlapping rectangles.Also even if the two rectangles only share a common point, they are still regarded as sharing common area.There can be a few same rectangles on the plane, they should be regarded as a few different rectangles.
The main point is rectangles can be added and deleted at any given instant.
Constraints :
Their can be total of 10^5 queries.And each coordinate can go from 1 to 10^9.
My approach : We know that Suppose we have two rectangles R1 and R2. Let (x1, y1) be the location of the bottom-left corner of R1 and (x2, y2) be the location of its top-right corner. Similarly, let (x3, y3) and (x4, y4) be the respective corner locations for R2. The intersection of R1 and R2 will be a rectangle R3 whose bottom-left corner is at (max(x1, x3), max(y1, y3)) and top-right corner at (min(x2, x4), min(y2, y4)).
If max(x1, x3) > min(x2, x4) or max(y1, y3) > min(y2, y4) then R3 does not exist, ie R1 and R2 do not intersect.
Now main problem with me that ma facing is say we have insert query of say (I X1 Y1 X2 Y2) and delete query of type(D index) which will delete rectangle inserted at index th query of insertion.How to handle them efficiently