Under construction

Still being built. Things may change

Piecewise Linear Function

Interview

Time limit1sMemory limit1024 MB

Summary
Given N points joined by line segments, report for each query x-coordinate k whether the piecewise linear function is increasing, decreasing, or flat there.
Level

Easy3 of 10

Topics
Binary search, Array
Solved
No attempts yet

Problem

Points NN are given on a two-dimensional coordinate plane. The position of the ii-th point is (xi,yi)(x_i, y_i), and xi<xi+1x_i < x_{i+1} holds for every ii with 1≤i<N1 \leq i < N. A linear function connecting point ii and point i+1i+1 is drawn. Let F(x)F(x) be the combination of the N−1N-1 linear functions defined on the intervals (x1,x2),(x2,x3),⋯ ,(xN−1,xN)(x_1, x_2), (x_2, x_3), \cdots, (x_{N-1}, x_N).

For example, when the points are (0,0)(0, 0), (1,5)(1,5), (2,4)(2,4), (3,3)(3,3), and (6,10)(6,10), the drawn function is shown below.

For each query, a real number kk is given. Determine whether F(x)F(x) is increasing or decreasing at x=kx=k.

Input

The first line contains the number of points NN. (2≤N≤100 000)(2\leq N \leq 100\,000)

From the second line onward, the NN lines each contain the coordinates xi,yix_i, y_i separated by a space. (−109≤xi,yi≤109; xi<xi+1)(-10^9 \leq x_i, y_i \leq 10^9;\ x_i < x_{i + 1})

The (N+1)(N+1)-th line contains the number of queries QQ. (1≤Q≤100 000)(1 \leq Q \leq 100\,000)

From the (N+2)(N+2)-th line onward, the QQ lines each contain a query kk. (x1<k<xN; k≠xi)(x_1 < k < x_N;\ k \neq x_i)

xix_i and yiy_i are integers. Each kk is given with at most one digit after the decimal point.

Output

For each query, print 11 if the linear function containing kk is increasing, −1-1 if it is decreasing, and 00 if it is neither. Print one answer per line, in query order.

Examples1

  1. Example 1

    Input
    5
    0 0
    1 5
    2 5
    3 3
    6 10
    3
    2.5
    4
    1.5
    
    Expected output
    -1
    1
    0