This page is still under construction.

Parts of this page are still being built. What you see may change.

Straight Lines 2

Time limit1sMemory limit128 MB

Summary
Given a possibly self-intersecting polygon and several lines, find the squared distance from each line to the polygon and print it as an exact irreducible fraction.
Level

Medium7 of 10

Topics
Geometry, Math, Binary search, Sorting
Solved
No attempts yet

Problem

The distance from a line to a polygon is the smallest distance between that line and any point of the polygon. Here the polygon means both its boundary (its edges) and its interior. The polygon does not have to be convex: vertices may repeat and the boundary may cross itself.

Write a program that:

  • reads a polygon and several lines from standard input,
  • for each line computes the distance from that line to the polygon,
  • writes the results to standard output.

Input

The first line contains two integers nn and mm (3≤n≤50 0003 \le n \le 50\,000, 1≤m≤50 0001 \le m \le 50\,000), separated by a space: the number of vertices of the polygon and the number of lines to analyze.

Each of the next nn lines contains two integers xix_i and yiy_i (−109≤xi,yi≤109-10^9 \le x_i, y_i \le 10^9), the coordinates of the ii-th vertex. Each pair of consecutive vertices, and also the last vertex together with the first, forms a side of the polygon.

Each of the next mm lines contains three integers AiA_i, BiB_i and CiC_i (−109≤Ai,Bi,Ci≤109-10^9 \le A_i, B_i, C_i \le 10^9, Ai2+Bi2>0A_i^2 + B_i^2 > 0), describing the line Aix+Biy+Ci=0A_i x + B_i y + C_i = 0.

Output

Print mm lines. The ii-th line must contain the square of the distance between the ii-th line and the polygon, written as an irreducible fraction: the numerator, a / sign, then the positive denominator. If the line touches or crosses the polygon the distance is 00, printed as 0/1.

Hint

Examples1

  1. Example 1

    Input
    8 2
    2 1
    6 1
    6 2
    3 2
    3 5
    5 5
    5 7
    2 7
    1 1 -2
    1 0 -6
    
    Expected output
    1/2
    0/1