Windows
InterviewTime limit1sMemory limit128 MB
Given windows in opening order, answer clicks by returning the most recently opened window covering each click point, or background if none does.
- Level
Easy3 of 10
- Topics
- Array, Brute force, Implementation, Simulation
- Solved
- No attempts yet
Problem
Emma is careless with her computer's desktop: she keeps opening windows and never closes the applications that created them. Her desktop becomes a cluttered pile in which some windows only peek out from behind others and some are hidden entirely. Because Emma leaves her machine on for days, the mess grows enormous. Your task is to determine which window (if any) is selected when Emma clicks a given point on the screen.
When Emma clicks, the selected window is the topmost window covering that point — that is, the most recently opened window that contains it. Clicking a window does not bring it to the front.
The screen has a resolution of pixels. The pixel in the upper-left corner of the desktop is at position , so the lower-right pixel is at . Rows are numbered top to bottom and columns left to right. A window is given by the position of its upper-left pixel together with its width and height ; it covers exactly the pixels in rows through and columns through .
Input
The input contains a sequence of desktop descriptions.
Each description begins with a line containing a positive integer (), the number of windows, followed by lines listing the windows in the order Emma opened them. Each window line contains four integers , , , and : is the row and column of the window's upper-left pixel (), and and are its width and height in pixels (). Every window lies entirely on the desktop, so no window is cropped.
After the window lines comes a line with a positive integer , the number of queries, followed by lines. Each query line contains two integers and , the row and column of a clicked location, which is always on the desktop.
The input ends with a line containing a single in place of the window count .
Output
For each desktop description, in the order given, first print a line Desktop k:, where is the desktop number starting from . Then print lines, one per query in order: print window k if the click selects the window numbered , or background if the click hits no window. Windows are numbered in the order Emma opened them. Remember that a query never changes which window is in front.