Mr. Engineer has installed a new security system for the National Jewelry Museum. For…
- User
Mr. Engineer has installed a new security system for the National Jewelry Museum. For this purpose, he has placed a number of lasers in different places of the museum so that if a thief touches the lasers, the alarm will be activated. For added security, the lasers are not fixed and change direction at the end of each minute. Pay attention that lasers have only two directions, vertical and horizontal. In fact, each of the lasers can be viewed as a point that covers the horizontal or vertical direction at any time. (Note that the lasers cover all the points in the same direction and in fact their coverage is a line and not a half line)
To test the security system, the engineer needs a program that takes the initial position of a thief and the position of one of the jewels in the museum and calculates the minimum time it takes for the thief to reach the jewel without hitting the lasers. It is assumed that in one minute the thief can reach all the points that do not need to pass through the laser. It is your duty to write the program requested by the engineer.
input The first line of the input contains two natural numbers n n, the number of museum lasers, and q q is the number of questions asked by the engineer.
in each of n n next line in order
t\in {- , ,|}
and two natural numbers x x and y y is said to mean the presence of a laser in coordinates ( x , y ) (x,y) is Variable t t indicates the state of the laser in the initial state (zero minute). If it is -, the laser is horizontal at the beginning of work (in the direction of the x-axis) and if | is vertical (along the y axis).
in each of q q- The next line is four natural numbers in order x s x s and y s y s and x g x g and y g y g
It is stated that ( x s , y s ) (x s ,y s ) initial coordinates of the thief and ( x g , y g ) (x g ,y g ) shows the coordinates of the gem.
It is guaranteed that no two lasers are in the same horizontal or vertical alignment.
For all queries, the thief's initial location and the jewel's location are guaranteed not to be in horizontal or vertical alignment with any of the lasers. It is guaranteed that all input numbers are in the range [
1 0 9 , 1 0 9 ] [−10 9 , 10 9 ] are located.
1 ≤ n , q ≤ 100
000 1 ≤ n, q ≤ 100 000
output Output included q q is a line that is a line i i-th answer to the question i i-m is Mr. Engineer.
Sub-issues Constraint score subproblem 1 15 n ≤ 50 n≤50 2 35 n ≤ 1
000 n≤1 000 350 without additional restrictions Example Sample entry 1 3 3
- 3 1 | 1 3
- 5 5 2 2 4 4 2 2 0 0 2 2 6 6 Plain text Sample output 1 0 1 1 Plain text Sample input 2 4 3
- 1 1
- 3 3
- Assistant