Space Exploration
Time limit2sMemory limit256 MB
Given N segment obstacles in the first quadrant and M rays from the origin, count how many segments no ray intersects, including exact endpoint touches.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Binary search
- Solved
- No attempts yet
Problem
In the near future, humanity can travel between stars and sets out to find a new home. After a long voyage the last wormhole is finally ahead, but it is full of radiation layers. If people pass through it as it is, many of them will be exposed to radiation.
Fortunately, humanity has a laser that can destroy radiation layers. The laser fires from its position as a ray and destroys every radiation layer it hits. Given the radiation layers inside the wormhole and the laser firing positions, write a program that computes how many radiation layers remain after all lasers are fired.
For convenience, the laser is located at . Each radiation layer is a line segment in the first quadrant of the 2D coordinate plane. A firing position is given as , which means the laser fires along the ray from toward .
The figure below shows two different laser shots at the same radiation layer.

In figure (a), the laser fired toward hits the radiation layer and destroys it. In figure (b), the laser fired toward misses the radiation layer and does not destroy it.
If a laser passes exactly through the start point or the end point of a radiation layer segment, the laser hits that layer. The laser is extremely thin, so you do not need to consider its thickness.
Input
The first line contains (), the number of radiation layers inside the wormhole. Each of the next lines describes the -th radiation layer () with the coordinates of the two endpoints of its segment, , , , , separated by spaces.
The next line contains (), the number of laser shots. Each of the next lines contains the firing position , of the -th laser (), separated by a space.
Every coordinate in the input is an integer from to , inclusive. The start point and the end point of a radiation layer segment can be the same.
Output
Print the number of radiation layers left inside the wormhole after all lasers are fired.