#P3122. [USACO15FEB] Fencing the Herd G

[USACO15FEB] Fencing the Herd G

Description

Farmer John needs your help deciding where to build a fence shaped as an infinitely long straight line to restrict the movement of his cows. He has selected several candidate positions for building the fence, and you need to determine which fences are useful. A fence is useful if and only if all cows lie on the same side of the fence. If any cow lies exactly on the fence line, then the fence is useless. Farmer John will ask you multiple times whether a fence is useful; for each query, output YES if the fence is useful, otherwise output NO.

Additionally, Farmer John may bring in new cows to join the herd. After a cow joins, it must be considered in all subsequent queries and must also lie on the same side of the fence as the other cows.

Input Format

The first line contains two positive integers n,qn, q, the initial number of cows and the number of queries.

The next nn lines each contain two integers x,yx, y, the initial positions of the cows.

The next qq lines each describe a query in one of the following formats:

  • 1 xx yy: a new cow joins the pasture at (x,y)(x, y).
  • 2 AA BB CC: Farmer John asks whether the fence Ax+By=CAx + By = C is useful.

Output Format

For each query of type 22, output YES if the fence is useful, otherwise output NO.

3 4 
0 0 
0 1 
1 0 
2 2 2 3 
1 1 1 
2 2 2 3 
2 0 1 1 

YES 
NO 
NO 


Hint

The line 2x+2y=32x + 2y = 3 places all three initial cows on the same side; however, adding the cow (1,1)(1, 1) on the other side makes it useless.

The line y=1y = 1 is useless because cows (0,1)(0, 1) and (1,1)(1, 1) lie exactly on it.


Constraints.

For 100%100\% of the testdata, it is guaranteed that 1n1051 \leq n \leq 10^5, 1q1051 \leq q \leq 10^5, all cows have distinct coordinates and satisfy 109x,y109-10^9 \leq x, y \leq 10^9, 109A,B109-10^9 \leq A, B \leq 10^9, 1018C1018-10^{18} \leq C \leq 10^{18}.

It is guaranteed that there is no fence with A=B=0A = B = 0.

Translated by ChatGPT 5