Fencing the Herd
Time limit2sMemory limit256 MB
The herd grows over time and each query asks whether every cow so far lies strictly on one side of the given line.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search
- Solved
- No attempts yet
Problem
Farmer John wants to build a fence in the shape of a straight line so his cows cannot wander so far. He has picked several candidate positions for it and needs to know which ones he can actually use. A fence is usable when every cow is on the same side of it. A fence is not usable when a cow lies directly on it. For each fence query, answer YES when the fence is usable and NO when it is not.
Farmer John also brings new cows into the herd from time to time. From the moment a new cow joins, every later fence query needs her on the same side as the rest of the herd for the fence to be usable.
Input
The first line contains () and (), separated by a space. They give the number of cows in the herd at the start and the number of operations.
Each of the next lines contains two space separated integers and , the position of one cow.
Each of the remaining lines holds one operation. A line 1 x y means a new cow joined the herd at position . A line 2 A B C asks whether the fence along the line is usable.
Every cow position in the whole input is distinct, and all of them satisfy . The fence queries satisfy and . No fence query has .
Output
For each fence query, print YES on its own line when the fence is usable, and NO otherwise.
Hint
One cow sitting on the line is enough to rule a fence out, even when every other cow is on one side of it.
The input and the output are large. Read the input with a fast reader and do not flush the output after every line.