Archery
Time limit1sMemory limit128 MB
Decide whether some spot on the archer line fires one straight shot through every horizontal target segment.
- Level
Medium7 of 10
- Topics
- Geometry, Intervals, Binary search
- Solved
- No attempts yet
Problem
Korea is famous for archery: its national teams have swept nearly every gold, silver, and bronze medal at the Olympic Games.
An archery exhibition will be held in Korea. As a ceremonial event, a master archer will try to shoot a single arrow that passes through every one of several paper target boards at once. Because an arrow flies in a straight line, whether the master can pierce all targets depends on where along the archer line he stands.
The picture below is a top-down view of the field. Every target is a line segment parallel to the archer line. Set up a coordinate system whose origin is the leftmost point of the archer line, with the archer line lying on the positive -axis.

In the figure, the master can pierce all targets from position B, but never from position A, because any ray from A meets at most 3 targets.
Given the width of the archer line and the positions of the targets, decide whether there is a spot on the archer line from which the master can pierce every target with one straight shot. You may assume the -coordinates of the targets are all different. If an arrow passes exactly through an endpoint of a target, it still counts as hitting that target.
Input
The first line contains the number of test cases ().
Each test case begins with a line holding an integer (), the width of the archer line. The next line holds an integer (), the number of target boards. Each of the following lines contains three integers , , (, ): is the -coordinate of the -th target, and and are the -coordinates of its leftmost and rightmost points. All are distinct.
Output
For each test case, print exactly one line: YES if some position on the archer line lets the master pierce every target with a single straight shot, otherwise NO.