P18012 [GCPC 2022] Mirror Madness
Description
Yesterday, a new attraction opened at the local amusement park: a mirror maze. The walls of this maze are covered with mirrors, and visitors can easily lose their way among the countless reflected images. The layout of the maze can be described by a polygon whose every edge is parallel to the $x$-axis or the $y$-axis.
On the opening day, many visitors got lost, and staff had to go in and help them find the exit. To figure out where visitors are most likely to get lost, the staff decided to install a monitoring system. The system sends an invisible laser beam through the maze close to the ground; by observing when and where the beam is blocked, they can track the visitors' movements.
The laser is emitted from a point on the boundary of the polygon, at an angle of $45^\circ$ to the walls. Whenever it hits a mirror, it reflects, turning by $90^\circ$. To make the monitoring system work, the staff plan to install a sensor at each of the first $m$ positions where the laser reflects. Find these positions.
Input Format
- The first line contains two integers $n$ and $m$ ($1\le n,m\le 5\cdot 10^5$), the number of vertices of the polygon and the number of reflections to record, respectively.
- Each of the next $n$ lines contains two integers $x$ and $y$, the coordinates of a vertex.
- The last line contains two integers $x_s$ and $y_s$, the coordinates of the laser's starting point.
The input also satisfies the following conditions:
- The vertices of the polygon are given in counterclockwise order.
- Adjacent edges share an endpoint. Other than that, the edges of the polygon do not touch or intersect each other.
- The edges of the polygon alternate between horizontal and vertical.
- The perimeter of the polygon (the sum of the lengths of its edges) does not exceed $10^6$.
- The absolute values of all coordinates in the input do not exceed $10^6$.
- Every coordinate of every vertex of the polygon is even, and exactly one of the two coordinates of the starting point is even, so the laser will never hit a vertex of the polygon.
- The starting point lies on the boundary of the polygon.
- The initial direction of the laser is $(1,1)$, pointing into the interior of the polygon.
Output Format
Output $m$ lines, each containing two integers $x$ and $y$, giving the coordinates of each reflection position in order.
Explanation/Hint
#### Sample 2 Explanation

Figure M.1: Illustration of Sample 2.
Translated by QwenWork