Mayor's House
Time limit2sMemory limit1024 MB
For each home location, find a route from city hall with at most two turns that never enters the interior of a closed rectangular block, or report NO.
Statement
The roads of the new district are planned as a rectangular grid. Every street is one of two types: streets running south to north, and streets running west to east. Parallel streets are spaced exactly 1 kilometer apart, so every block is 1 km by 1 km. Every road can be used in either direction.
After the roads were built, the layout turned out to be inconvenient. One block is not enough for a large factory, another large building, or a park. The city hall decided to assign each large project a rectangular block made of several neighboring blocks. After a project is built, all roads inside its block are closed to traffic. Roads on the boundary of a block stay open. Two blocks that only touch do not close the passage between them.
The mayor has k possible locations for his future home. The city hall wants to know how complicated the route from city hall to the home is. A route is considered complicated if it needs more than two turns, left or right, in total. A car cannot turn more than once at the same intersection, including a U-turn. The length of the route does not matter, and the home can be approached from any side. The mayor's car always starts at city hall facing north, and it can turn right or left right away but cannot make a U-turn.
For each possible home location, find a route from city hall with at most two turns, or report that no such route exists. The number of turns does not need to be minimized.
Input
The first line contains two integers n and k (0 \le n \le 100000, 1 \le k \le 10), the number of blocks given to large projects and the number of possible home locations.
Each of the next n lines contains four integers u1, v1, u2, v2 (, ). These are the street numbers at which two opposite corners of a closed block meet.
Each of the last k lines contains two integers x_i and y_i (, , and or ), the possible home location. Positive x is east of city hall, and positive y is north of it.
City hall and none of the home locations lie inside a closed block. Closed blocks may overlap.
Output
For each home location, in the order given in the input, print the answer.
If no route with at most two turns exists, print a single line containing NO.
Otherwise print YES on the first line, then the number of turns t (0 \le t \le 2) on the second line. Then print t lines describing the turns in the order they are made. Each line contains three integers x, y, and d, where x and y are the street numbers of the intersection and d is -1 for a left turn or 1 for a right turn.
The coordinates of the turning intersections do not exceed in absolute value. If several shortest valid routes exist, print any of them.
Hint
The figure below illustrates the second example.
