Hide

Problem H
Antimatter Rain

You’ve heard of acid rain but have you heard of antimatter rain? Antimatter rain is so potent that when it comes into contact with another object, it immediately disintegrates both itself and the object. Kayla’s job as a SpaceFleet Researcher is gathering weather data on exotic planets. This time, their assignment is to monitor the antimatter rainfall.

Sensors are set up in the planet’s atmosphere and are about to be rained on with antimatter rain. Oh no! Kayla monitors a single 2D section. Each sensor is either a single horizontal strip or a single point. When one or more antimatter droplet fall on a single sensor, all of those droplets and the sensor disintegrate simultaneously. That is, they disappear. All other droplets will drop past where the sensor used to be.

Kayla sees all the antimatter rain drops the moment before they all start to fall. All droplets fall at exactly the same rate.

For each droplet, Kayla wants to know if and where it will disintegrate. Help them out with this demanding task!

\includegraphics[width=0.4\textwidth ]{antimatter.pdf}

Illustration of the first sample. The vertical lines connect the drops to the sensor they hit. The drop with no associated vertical line will not hit any sensor.

Input

The first line of input contains two integers $D$ ($1 \leq D \leq 100\, 000$), which is the number of antimatter droplets, and $S$ ($1 \leq S \leq 100\, 000$), which is the number of sensors.

The next $D$ lines describe the droplets, in order. Each of these lines contains two integers $x$ ($1 \leq x \leq 10^9$), which is the $x$-coordinate of the droplet and $y$ ($1 \leq y \leq 10^9$), which is the $y$-coordinate of the droplet.

The next $S$ lines describe the sensors. Each line contains three integers $x_1$, $x_2$ ($1 \leq x_1 \leq x_2 \leq 10^9$), which is the leftmost and the rightmost $x$-coordinate of the sensor, and $y$ ($1 \leq y \leq 10^9$), which is the $y$-coordinate of the sensor.

It is guaranteed that no two drops will start in the same location, no drop will start on any sensor, and no two sensors touch (not even at a single point).

Output

For each droplet, in order, display a single number indicating the $y$-coordinate that it will disintegrate. If the droplet does not disintegrate, display $0$ instead. These values should appear on separate lines.

Sample Input 1 Sample Output 1
5 3
1 8
2 3
2 8
5 8
5 9
3 6 6
1 7 4
1 3 1
4
1
4
6
0
Sample Input 2 Sample Output 2
6 3
1 2
4 8
5 10
6 10
7 10
8 10
1 1 1
3 4 3
5 7 9
1
3
9
9
9
0

Please log in to submit a solution to this problem

Log in