#P1003. Carpet Overlap Query
Carpet Overlap Query
Carpet Overlap Query
There are \(n\) rectangular carpets placed sequentially in the first quadrant of the coordinate plane. Carpets are laid in increasing order of their indices, and a later carpet will cover any previously placed carpets that overlap it.
Each carpet is defined by its bottom-left and top-right coordinates. A carpet covers a point \((x,y)\) (including the boundaries) if and only if \[ x_{1} \le x \le x_{2} \quad \text{and} \quad y_{1} \le y \le y_{2}, \] where \((x_{1}, y_{1})\) and \((x_{2}, y_{2})\) represent the bottom-left and top-right corners respectively.
Given several query points, for each query, determine the index of the topmost carpet covering that point. If no carpet covers the point, output 0.
inputFormat
The first line contains two integers \(n\) and \(q\): the number of carpets and the number of queries respectively.
Each of the next \(n\) lines contains four integers: \(x_1\), \(y_1\), \(x_2\), \(y_2\) — the coordinates of the bottom-left and top-right corners of a carpet.
Each of the following \(q\) lines contains two integers \(x\) and \(y\) representing a query point.
outputFormat
For each query, output a single line containing the index of the carpet that is on top covering the given point. If no carpet covers the point, output 0.
sample
3 3
1 1 4 4
2 2 5 5
3 0 6 3
3 3
5 5
0 0
3
2
0
</p>