Hide

Problem H
Water Decor

/problems/waterdecor/file/statement/en/img-0001.jpg

The Pokemon Aquarium is finally remodeling! To commemorate its 5th year anniversary, the Aquarium has built a massive water-based decoration!

The decoration is quite an interesting design and can be modeled as a series of non-overlapping circles in the square (0,0) to (106,106). For all integers 0xi106, there exists a water dispenser at (xi,) that dispenses water directly downwards.

Water always flows directly downwards. If it hits a circle, it will flow differently depending on where it hits the circle.

  1. If it hits the left half of the circle, it will flow along the left side and continue flowing downwards from the left half

  2. If it hits the right half of the circle, it will flow along the right side and continue flowing downwards from the right half

  3. If it hits the top of the circle, it will flow along both the left and right side of the circles and continue flowing downwards from both halves

Squirtle loves to watch the water flow in the decoration. He wonders, if all the water dispensers between x=L to x=R are activated, how many distinct x coordinates will water reach at y=0? Given Q queries, please help Squirtle answer this puzzling question!

Input

The first line of input contains two integers, N and Q. The next N lines contain three integers xi,yi,ri, denoting a circle of radius ri at (xi,yi). The next Q lines contain two integers Lj,Rj, denoting a query of water dispensers between x=Lj to x=Rj for the jth query.

1N105
1Q2105
1<xi,yi<106.
1ri5105
0Lj,Rj106

It is guaranteed all circles will be fully contained inside the square with a bottom-left corner at (0,0) and upper-right corner at (106,106), and all circles are non-intersecting.

Output

Output Q integers, the jth of which is a single integer representing the number of distinct x coordinates that water can flow to if the water dispensers from x=Lj to x=Rj.

Sample Input 1 Sample Output 1
1 3
1 1 1
0 0
0 1
1 1
1
2
2
Sample Input 2 Sample Output 2
2 4
1 1 1
4 5 3
0 0
0 1
1 1
5 6
1
2
2
1
Hide

Please log in to submit a solution to this problem

Log in