Canadian Computing Competition: 2005 Stage 2, Day 2, Problem 3
You probably remember from Stage that computers have a mouse and
sometimes, if you really have to, you have a bunch of windows that you
can click on.
In particular, you will have a screen which has
rows and
columns. You have
rectangular windows, defined by the "top-left"
coordinates
and "bottom-right" coordinates
.
Note that you can assume that
and
(thus, you don't have empty windows).
It is worth noting that a window includes all points on its borders:
that is, the window defined by and
includes exactly the points
such that
and
.
If two windows overlap, the one which is on top of the other window will be listed later in the sequence (not necessarily immediately after, however). Here comes the mouse part.
You also have a mouse that can click on windows. Initially, the mouse is
at position (the bottom-left corner of the screen). The mouse
will then be told to move to a particular position (say
, where
and
) and click. When the mouse clicks, the
window which is visible at that position moves to the top (that is, the
entire window becomes visible, possibly hiding some other windows).
There will be
such mouse clicks.
Your job is to indicate which of the windows is "in focus" (i.e.,
most recently clicked on) after each mouse move.
Input Specification
The first line of input consists of an integer , the number of columns.
The second line of input consists of an integer , the number of rows.
The third line of input consists of the number , the number of windows.
On each of the next lines, there are four integers
followed by
followed by
followed by
, indicating the
"top-left" and "bottom-right" coordinates of this window. (These windows
are numbered from
to
).
On the next line is the integer . On
each of the next
lines will be two integers,
followed by
,
indicating the new position of the mouse.
Output Specification
The output is lines long, each line containing an integer
such
that
. If line
contains the integer
,
that indicates that after the
th mouse move, the window
was just
clicked on (and has moved to the top). If, instead,
, then
there was no window at that position.
Sample Input
200
100
3
50 50 80 20
70 60 180 10
10 90 100 40
3
60 20
150 90
150 30
Sample Output
1
0
2
Explanation
The screen has width and height
. There are three windows on the
screen, and initially, we have the following configuration:
After the mouse clicks at , we have:
Since there is no window at position ,
is outputted.
Once we click at position , that moves window
into focus, to
get the following picture.
Comments