eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

Windows

Emma is not very tidy with the desktop of her computer. She has the habit of opening windows on the screen and then not closing the application that created them. The result, of course, is a very cluttered desktop with some windows just peeking out from behind others and some completely hidden. Given that Emma doesn’t log off for days, this is a formidable mess. Your job is to determine which window (if any) gets selected when Emma clicks on a certain position of the screen. Emma’s screen has a resolution of \textbf{10^6} by \textbf{10^6}. When each window opens its position is given by the upper-left-hand corner, its width, and its height. (Assume position (\textbf{0}, \textbf{0}) is the location of the pixel in the upper-left-hand corner of her desktop. So, the lower-right-hand pixel has location (\textbf{999999}, \textbf{999999}).) \InputFile Input for each test case is a sequence of desktop descriptions. Each description consists of a line containing a positive integer \textit{\textbf{n}}, the number of windows, followed by \textit{\textbf{n}} lines, \textit{\textbf{n}} ≤ \textbf{100}, describing windows in the order in which Emma opened them, followed by a line containing a positive integer \textit{\textbf{m}}, the number of queries, followed by \textit{\textbf{m}} lines, each describing a query. Each of the \textit{\textbf{n}} window description lines contains four integers \textit{\textbf{r}}\textit{, }\textit{\textbf{c}}\textit{, }\textit{\textbf{w}}\textit{,} and \textit{\textbf{h}}, where (\textit{\textbf{r}}\textit{, }\textit{\textbf{c}}) is the row and column of the upper left pixel of the window, \textbf{0} ≤ \textit{\textbf{r}}\textit{, }\textit{\textbf{c}} ≤ \textbf{999999}, and \textit{\textbf{w}} and \textit{\textbf{h}} are the width and height of the window, in pixels, \textbf{1} ≤ \textit{\textbf{w}}\textit{, }\textit{\textbf{h}}. All windows will lie entirely on the desktop (i.e., no cropping). Each of the \textit{\textbf{m}} query description lines contains two integers \textit{\textbf{cr}} and \textit{\textbf{cc}}, the row and column number of the location (which will be on the desktop). The last test case is followed by a line containing \textbf{0}. \OutputFile Using the format shown in the sample, for each test case, print the desktop number, beginning with \textbf{1}, followed by \textit{\textbf{m}} lines, one per query. The \textit{\textbf{i}}-th line should say either "window \textit{\textbf{k}}", where \textit{\textbf{k}} is the number of the window clicked on, or "background" if the query hit none of the windows. We assume that windows are numbered consecutively in the order in which Emma opened them, beginning with \textbf{1}. Note that querying a window does not bring that window to the foreground on the screen.
Лимит времени 1 секунда
Лимит использования памяти 32 MiB
Входные данные #1
3
1 2 3 3
2 3 2 2
3 4 2 2
4
3 5
1 2
4 2
3 3
2
5 10 2 10
100 100 100 100
2
5 13
100 101
0
Выходные данные #1
Desktop 1:
window 3
window 1
background
window 2
Desktop 2:
background
window 2
Источник 2009 East Central Regional Contest