8049: Fencing the Herd 围住牛群

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:5 通过:2

题目描述

农夫约翰需要你的帮助来决定在哪里建一个直线形的围栏来限制他的奶牛的活动。

他考虑了若干个建造围栏的位置,你需要帮助他确定其中哪些位置建起的围栏可用。

如果所有奶牛都在围栏的同一侧,则认为围栏是可用的。

如果有奶牛直接躺在围栏上,则认为围栏是不可用的。

约翰将询问你许多建造围栏的位置,对于每个查询,如果查询位置可用,则输出 YES 否则输出 NO。

另外需要注意,约翰有时会将新的奶牛赶入牛群。

当一头新的奶牛加入牛群中后,此后的所有询问都将要求它与其他奶牛处在围栏的同一侧,围栏方可使用。

输入格式

第一行包含两个整数 N 和 Q,分别表示初始牛群中牛的数量以及查询数量。

接下来 N 行用来描述初始牛群中每头牛的位置,每行包含两个整数 x,y,表示其中一头奶牛的位置横纵坐标。

接下来 Q 行,每行包含查询,要么在牛群中加入一头新奶牛,要么询问一个位置是否可用来建立围栏。如果格式为 1 x y,表示在 (x,y) 处增加一头奶牛。如果格式为 2 A B C,表示询问建立一个 Ax + By = C 的围栏,是否可用。

所有奶牛的位置都不相同。

输出格式

对于每个关于围栏的询问,输出一个回答,占一行。

如果围栏可用则输出 YES,否则输出 NO。

数据范围

1≤N,Q≤105,
−109≤x,y≤109,
−109≤A,B≤109,
−1018≤C≤1018
保证不存在 A=B=0 的情况。

输入样例:

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 

样例解释

2x+2y=3 处的围栏可使三头初始奶牛位于同一侧。

但是,随着位于 (1,1) 处的奶牛的加入,该围栏无法将它与其他三头奶牛分在同一侧内,所以该围栏就不可用了。

Y=1 处的围栏无法使用,因为位于 (0,1) 和 (1,1) 处的奶牛直接躺在了它的上面。

Farmer John needs your help deciding where to build a fence in the shape of a straight line to help restrict the movement of his cows. He has considered several possible fence locations and needs your help to determine which of these are usable, where a fence is considered usable if all of the cows are on the same side of the fence. A fence is not usable if there is a cow that lies directly on it. FJ will be asking you a number of queries regarding possible fence locations; a query should be answered "YES" if it corresponds to a usable fence location, "NO" otherwise.

Additionally, FJ may occasionally bring new cows into the herd. When a new cow joins the herd, all fence queries from that point onward will require her to be on the same side of a fence as the rest of the herd for the fence to be usable.

输入格式

The first line of input contains N (1 <= N <= 100,000) and Q (1 <= Q <= 100,000) separated by a space. These give the number of cows initially in the herd and the number of queries, respectively.

The following N lines describe the initial state of the herd. Each line will contain two space separated integers x and y giving the position of a cow.

The remaining Q lines contain queries either adding a new cow to the herd or testing a fence for usability. A line of the form "1 x y" means that a new cow has been added to the herd at position (x, y). A line of the form "2 A B C" indicates that FJ would like to test a fence described by the line Ax + By = C.

All cow positions will be unique over the whole data set and will satisfy (-10^9 <= x, y <= 10^9). Additionally the fence queries will satisfy -10^9 <= A, B <= 10^9 and -10^18 <= C <= 10^18. No fence query will have A = B = 0.

输出格式

For each fence query, output "YES" if the fence is usable. 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