#P3122. Fence Placement for Cow Containment
Fence Placement for Cow Containment
Fence Placement for Cow Containment
Farmer John needs help deciding where to build an infinitely long straight fence to enclose his cows. He has selected several potential positions for the fence, and you need to determine which fences are useful. A fence is considered useful if and only if all cows lie strictly on one side of the fence. Note that if any cow lies exactly on the fence, then the fence is not useful.
The fence is represented by the line equation \(Ax+By+C=0\). For a fence query, if the value \(f(x,y)=Ax+By+C\) evaluated at every cow in the herd is either all positive or all negative, then the fence is useful (YES
). Otherwise, it is not (NO
).
Furthermore, Farmer John may add new cows to his herd. Once a cow is added, it will be considered in all subsequent fence queries.
inputFormat
The input begins with an integer \(n\) denoting the number of initial cows. Each of the next \(n\) lines contains two space-separated integers, representing the coordinates of a cow.
The next line contains an integer \(q\) representing the number of queries. Each of the following \(q\) lines is in one of the two formats below:
Q A B C
This represents a fence query, where the fence is defined by the line \(Ax+By+C=0\).
A x y
This represents the addition of a new cow at the coordinates \((x, y)\). The new cow will be taken into account in subsequent queries.
outputFormat
For each fence query (lines starting with Q
), output a single line containing YES
if the fence is useful (i.e. all cows lie strictly on one side of the line), or NO
otherwise.
sample
3
0 0
1 1
2 2
3
Q 1 -1 0
A 1 0
Q 1 -1 0
NO
NO
</p>