Http://www.codeforces.com/problemset/problem/70/D
Two operations
1: Add a vertex to form a new convex hull
2: Determine whether a point is in a convex hull
There are two ways to do this, but they are similar, all based on the convex hull method.
For example, when a convex packet is obtained in a horizontal order, there will be two convex lines, one convex line, and the other convex line, then, to judge a point in the convex package is to determine whether the point is below the convex line and whether it is above the convex line.
As shown in, it is a convex line. The new point now is under the line, that is, outside the convex bag. Therefore, we need to find two adjacent points p x in the horizontal order, and start from P on the left, use the cross product to determine the continuous deletion points. The right side is similar .. The last two red lines are the edges of the new convex hull, and p q X is deleted due to the addition of the now vertex.
When adding a vertex, we need to find two adjacent vertices in the horizontal order of the convex line, and then delete the vertices on both sides until the convex packet is defined.
You can use the Balance Tree to find two adjacent points. It is much easier to use STL.
Note: For a small detail, no reference is added when the parameter is passed, so it's time to directly use TLE.
# Include <cstdio> # include <map> # include <algorithm> using namespace STD; typedef pair <int, int> PII; typedef long LLD; # define MP make_pair # define x first # define y secondmap <int, int> convex [2]; Map <int, int>: iterator P, IT, it1, it2, q; LLD cross (pii a, pii B, PII c) {return (LLD) (B. x-. x) * (C. y-. y)-(LLD) (B. y-. y) * (C. x-. x);} bool judge (Map <int, int> & St, int X, int y) {If (! St. Size () return false; If (St. Find (x )! = ST. end () return y> = sT [X]; If (x <St. begin ()-> X | (-- st. end ()-> x <X) return false; P = ST. lower_bound (x); q = P; q --; return cross (MP (x, y), * q, * P)> = 0;} void insert (Map <int, int> & St, int X, int y) {If (Judge (St, x, y) return; ST [x] = y; P = ST. upper_bound (x); it1 = it2 = It = P; it --; it1 = it; it1 --; it2 = it1; it2 --; If (P! = ST. End () {q = P; q ++; while (Q! = ST. end () & cross (MP (x, y), * q, * P)> = 0) {St. erase (p); P = Q; q ++ ;}} if (IT = ST. begin () | it1 = ST. begin () return; while (it1! = ST. begin () & cross (MP (x, y), * it1, * it2)> = 0) {St. erase (it1); it1 = it2; it2 -- ;}} int main () {int Q, op, X, Y; scanf ("% d", & Q ); while (Q --) {scanf ("% d", & OP, & X, & Y); If (OP = 1) {insert (convex [0], x, y); insert (convex [1], X,-y);} else {bool ans1 = judge (convex [0], x, Y); bool ans2 = judge (convex [1], X,-y); If (ans1 & ans2) puts ("yes "); elseputs ("no") ;}} return 0 ;}