PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000145. Rào chắn đàn bò (Fencing the Herd)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Rào chắn đàn bò (Fencing the Herd)

Fencing the Herd

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

Farmer John wishes to construct a straight fence that keeps all existing cows strictly on the same side. Initially there are nn cows, each at a distinct integer-coordinate point (x,y)(x,y). Process qq events in chronological order:

  • 1 x y adds a cow at (x,y)(x,y).
  • 2 A B C considers the line Ax+By=CAx+By=C. The fence is valid if every current cow is strictly on the same side (inside the same open half-plane). A cow lying directly on the line invalidates the fence.

All cow coordinates throughout the input are distinct. Evaluate each fence query using the herd that exists at that moment.

Input

  • The first line contains n,qn,q.
  • The following nn lines contain the coordinates x,yx,y of the initial cows.
  • Each of the next qq lines starts with an operation type tt: either 1 x y for a new cow, or 2 A B C for a fence query.

Output

For each type 2 event, print YES if all current cows lie strictly on one side, otherwise NO. Type 1 events produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 1≤q≤501\le q\le 50; all cow positions distinct; −109≤x,y,A,B≤109-10^9\le x,y,A,B\le10^9; −1018≤C≤1018-10^{18}\le C\le10^{18}; type 2 has (A,B)≠(0,0)(A,B)\ne(0,0).
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 1≤q≤30001\le q\le 3000; all cow positions distinct; −109≤x,y,A,B≤109-10^9\le x,y,A,B\le10^9; −1018≤C≤1018-10^{18}\le C\le10^{18}; type 2 has (A,B)≠(0,0)(A,B)\ne(0,0).
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤q≤1000001\le q\le 100000; all cow positions distinct; −109≤x,y,A,B≤109-10^9\le x,y,A,B\le10^9; −1018≤C≤1018-10^{18}\le C\le10^{18}; type 2 has (A,B)≠(0,0)(A,B)\ne(0,0).

Examples

Example 1

Input

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

Output

YES
NO
NO

Explanation

Initially 2x+2y2x+2y equals 0,2,20,2,2 at the three cow positions, all below 33: YES. Adding (1,1)(1,1) introduces the value 4>34>3, so the same fence is invalid: NO. The final line y=1y=1 contains existing cows, so NO.