1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
| #include <bits/stdc++.h> #define maxn 800005 #define int long long using namespace std;
const long double eps = 1e-8;
int sgn(long double x){ if(fabs(x) <= eps) return 0; return x > 0 ? 1 : -1; }
template<typename T> struct TP{ T x, y; TP(){} TP(T _x, T _y){ x = _x; y = _y; } TP operator -() const { return {-x, -y}; } friend TP operator +(const TP &a, const TP &b){ return {a.x + b.x, a.y + b.y}; } friend TP operator -(const TP &a, const TP &b){ return {a.x - b.x, a.y - b.y}; } friend T operator *(const TP &a, const TP &b){ return a.x * b.x + a.y * b.y; } friend T operator ^(const TP &a, const TP &b){ return a.x * b.y - a.y * b.x; } friend bool operator ==(const TP &a, const TP &b){ return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0; } friend bool operator <(const TP &a, const TP &b){ if(sgn(a.x - b.x) == 0) return sgn(a.y - b.y) < 0; return sgn(a.x - b.x) < 0; } TP operator *(const long double &k) const{ return {x * k, y * k}; } TP operator /(const long double &k) const{ return {x / k, y / k}; } int toleft(const TP &a) const { auto t = (*this) ^ a; return (t > eps) - (t < -eps); } long double angle(){ return atan2(y, x); } long double len() const { return sqrt(len2()); } long double dis(const TP &a) const { return sqrt(dis2(a)); } T len2() const { return (*this) * (*this); } T dis2(const TP &a) const { return TP(x - a.x, y - a.y).len2(); } long double ang(const TP &a) const { return acos(max(-1.0, min(1.0, ((*this) * a) / (len() * a.len())))); } TP rot(const long double rad) const { return {x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad)}; } TP rot(const long double cosr,const long double sinr) const { return {x * cosr - y * sinr, x * sinr + y * cosr}; } TP trunc(long double r){ long double l = len(); if(!sgn(l)) return (*this); r /= l; return {x * r, y * r}; } void input(){ cin >> x >> y; } void print(){ cout << "[Point]\n"; cout << x << " " << y << '\n'; } }; using Point = TP<long double>;
template<typename T> struct TL{ TP<T> s, e; TL(){} TL(TP<T> _s, TP<T> _e){ s = _s; e = _e; } friend T operator *(const TL &la, const TL &lb){ return (la.e - la.s) * (lb.e - lb.s); } friend T operator ^(const TL &la, const TL &lb){ return (la.e - la.s) ^ (lb.e - lb.s); } friend bool operator ==(const TL &la, const TL &lb){ return la.parallel(lb) && la.isOnSeg(lb.s); } long double length(){ return (e - s).len(); } long double disLine(const TP<T> &p) const { return fabs((p - s) ^ (e - s)) / length(); } long double disSeg(const TP<T> &p) const{ if(sgn((p - s) * (e - s)) < 0 || sgn((p - e) * (s - e)) < 0){ return min(p.dis(s), p.dis(e)); } return disLine(p); } TP<T> proj(const TP<T> &p) const { return s + (((e - s) * ((e - s) * (p - s))) / ((e - s).len2())); } TP<T> symmetryPoint(TP<T> p){ Point q = proj(p); return Point(2 * q.x - p.x, 2 * q.y - p.y); } bool parallel(TL v){ return sgn((e - s) ^ (v.e - v.s)) == 0; } TP<T> crosspoint(TL v){ auto a1 = (v.e - v.s) ^ (s - v.s); auto a2 = (v.e - v.s) ^ (e - v.s); return {(s.x * a2 - e.x * a1) / (a2 - a1), (s.y * a2 - e.y * a1) / (a2 - a1)}; } int isOnSeg(const TP<T> &p){ if(p == s || p == e) return -1; return sgn((p - s) ^ (e - s)) == 0 && sgn((p - s) * (p - e)) <= 0; } int segCrossSeg(TL v){ int d1 = sgn((e - s) ^ (v.s - s)); int d2 = sgn((e - s) ^ (v.e - s)); int d3 = sgn((v.e - v.s) ^ (s - v.s)); int d4 = sgn((v.e - v.s) ^ (e - v.s)); if((d1 ^ d2) == -2 && (d3 ^ d4) == -2) return 2; return (d1 == 0 && sgn((v.s - s) * (v.s - e)) <= 0) || (d2 == 0 && sgn((v.e - s) * (v.e - e)) <= 0) || (d3 == 0 && sgn((s - v.s) * (s - v.e)) <= 0) || (d4 == 0 && sgn((e - v.s) * (e - v.e)) <= 0); } int lineCrossSeg(TL v){ int d1 = sgn((e - s) ^ (v.s - s)); int d2 = sgn((e - s) ^ (v.e - s)); if((d1 ^ d2) == -2) return 2; return (d1 == 0 || d2 == 0); } int lineRelation(TL v){ if((*this).parallel(v)){ return v.toleft(s) == 0; } return 2; } int toleft(const TP<T> &p) const { int c = sgn((p - s) ^ (e - s)); if(c < 0) return 1; else if(c > 0) return -1; else return 0; } void print(){ cout << "[Line]\n"; cout << s.x << " " << s.y << " " << e.x << " " << e.y << '\n'; } }; using Line = TL<long double>;
const long double PI = acos(-1.0); template<typename T> struct TC{ TP<T> c; long double r; TC(){} TC(TP<T> _c, long double _r){ c = _c; r = _r; } TP<T> point(long double a) { return TP<T>(c.x + cos(a) * r, c.y + sin(a) * r); } long double area(){ return PI * r * r; } int relationCircle(TC v){ long double d = c.dis(v.c); if(sgn((d - r - v.r)) > 0) return 5; if(sgn((d - r - v.r)) == 0) return 4; long double l = fabs(r - v.r); if(sgn((d - r - v.r)) < 0 && sgn(d - l) > 0) return 3; if(sgn(d - l) == 0) return 2; if(sgn(d - l) < 0) return 1; } long double areaCircle(TC v){ int rel = relationCircle(v); if(rel >= 4) return 0.0; if(rel <= 2) return min(area(), v.area()); long double d = c.dis(v.c); long double hf = (r + v.r + d) / 2.0; long double ss = 2 * sqrt(hf * (hf - r) * (hf - v.r) * (hf - d)); long double a1 = acos((r * r + d * d - v.r * v.r) / (2.0 * r * d)); a1 = a1 * r * r; long double a2 = acos((v.r * v.r + d * d - r * r) / (2.0 * v.r * d)); a2 = a2 * v.r * v.r; return a1 + a2 - ss; } }; using Circle = TC<long double>;
template<typename T> struct TG{ vector<TP<T>> p; size_t nxt(const size_t i) const {return i == p.size() - 1 ? 0 : i + 1;} size_t pre(const size_t i) const {return i == 0 ? p.size() - 1 : i - 1;} T getArea2(){ int siz = p.size(); T sum = 0; for(int i = 0; i < siz; i++){ sum += (p[i] ^ p[(i + 1) % siz]); } return sum; } pair<bool, int> winding(const Point &a) { int cnt = 0; for(int i = 0; i < p.size(); i++){ Point u = p[i], v = p[nxt(i)]; if(sgn((a - u) ^ (a - v)) == 0 && sgn((a - u)*(a - v)) <= 0) return {true, 0}; if(sgn(u.y - v.y) == 0) continue; Line uv = {u, v - u}; if(u.y < v.y - eps && uv.toleft(a) <= 0) continue; if(u.y > v.y + eps && uv.toleft(a) >= 0) continue; if(u.y < a.y - eps && v.y >= a.y - eps) cnt++; if(u.y >= a.y - eps && v.y < a.y - eps) cnt--; } return {false, cnt}; } void print(){ cout << "[Polygon]\n"; for(int i = 0; i < p.size(); i++){ cout << i << " " << p[i].x << " " << p[i].y << '\n'; } } }; using Polygon = TG<long double>;
void adjustConvexHull(vector<Point> &P, vector<Point> &tmp){ int n = P.size(); tmp.resize(n); int pos = -1; long double minX = 1e60, maxY = -1e60; for(int i = 0; i < n; i++){ if(P[i].x < minX || (fabs(P[i].x - minX) <= eps && P[i].y > maxY)){ pos = i; minX = P[i].x; maxY = P[i].y; } } int cnt = 0; for(int i = pos; i < n; i++) tmp[cnt++] = P[i]; for(int i = 0; i < pos; i++) tmp[cnt++] = P[i]; for(int i = 0; i < n; i++) P[i] = tmp[i]; }
#define bk1(x) (x.back()) #define bk2(x) (*(x.rbegin() + 1)) void findConvexHull(vector<Point> p, vector<Point> &ans){ vector<Point> st; sort(p.begin(), p.end(), [&](const Point &A, const Point &B){ return sgn(A.x - B.x) ? A.x < B.x : A.y < B.y; }); for(Point u : p){ while(st.size() > 1 && ((bk1(st) - bk2(st)).toleft(u - bk2(st))) <= 0){ st.pop_back(); } st.push_back(u); } int k = st.size(); p.pop_back(); reverse(p.begin(), p.end()); for(Point u : p){ while(st.size() > k && ((bk1(st) - bk2(st)).toleft(u - bk2(st))) <= 0){ st.pop_back(); } st.push_back(u); } st.pop_back(); ans.clear(); for(auto x : st) ans.push_back(x); }
bool argcmpC(const Point &a, const Point &b){ auto Quad = [](const Point &a){ if(a.y < -eps) return 1; if(a.y > +eps) return 4; if(a.x < -eps) return 5; if(a.x > +eps) return 3; return 2; }; int qa = Quad(a), qb = Quad(b); if(qa != qb) return qa < qb; auto cross = (a ^ b); return cross > eps; }
vector<pair<Point, int>> polarUniqueTrans(vector<Point> &p){ map<Point, int, decltype(&argcmpC)> uni{&argcmpC}; vector<pair<Point, int>> res; for(auto x : p) uni[x]++; for(auto x : uni) res.push_back(x); return res; }
long double functionVal(long double x){ return 0; } long double simp(long double l, long double r){ long double mid = (l + r) / 2.0; return (r - l) * (functionVal(l) + 4 * functionVal(mid) + functionVal(r)) / 6.0; }
long double asr(long double l, long double r, long double ans){ long double mid = (l + r) / 2.0; long double vL = simp(l, mid), vR = simp(mid, r), tmp = vL + vR - ans; if(fabs(tmp) <= eps) return ans; else return asr(l, mid, vL) + asr(mid, r, vR); }
int getCircleTangents(Circle A, Circle B, vector<Point> &a, vector<Point> &b){ int cnt = 0; if (A.r < B.r) { swap(A, B); swap(a, b); } double d2 = (A.c.x - B.c.x) * (A.c.x - B.c.x) + (A.c.y - B.c.y) * (A.c.y - B.c.y); double rdiff = A.r - B.r; double rsum = A.r + B.r; if (sgn(d2 - rdiff * rdiff) < 0) return 0; double base = atan2(B.c.y - A.c.y, B.c.x - A.c.x); if (sgn(d2) == 0 && sgn(A.r - B.r) == 0) return -1; if (sgn(d2 - rdiff * rdiff) == 0) { a.push_back(A.point(base)); b.push_back(B.point(base)); cnt++; return cnt; } double ang = acos(rdiff / sqrt(d2)); a.push_back(A.point(base + ang)); b.push_back(B.point(base + ang)); a.push_back(A.point(base - ang)); b.push_back(B.point(base - ang)); cnt += 2; if(sgn(d2 - rsum * rsum) == 0){ a.push_back(A.point(base)); b.push_back(B.point(PI + base)); cnt++; } else if(sgn(d2 - rsum * rsum) > 0){ double ang = acos(rsum / sqrt(d2)); a.push_back(A.point(base + ang)); b.push_back(B.point(PI + base + ang)); a.push_back(A.point(base - ang)); b.push_back(B.point(PI + base - ang)); cnt += 2; } return cnt; }
Circle inversionC2C(Point O, long double R, Circle A){ long double OA = (A.c - O).len(); long double RB = 0.5 * ((1 / (OA - A.r)) - (1 / (OA + A.r))) * R * R; long double OB = OA * RB / A.r; long double Bx = O.x + (A.c.x - O.x) * OB / OA; long double By = O.y + (A.c.y - O.y) * OB / OA; return Circle(Point(Bx, By), RB); }
Circle inversionL2C(Point O, long double R, Point A, Point B){ Point P = Line(A, B).proj(O); long double d = (O - P).len(); long double RB = R * R / (2 * d); Point VB = (P - O) / d * RB; return Circle(O + VB, RB); }
Line inversionC2L(Point O, long double R, Circle A){ long double angle = (O - A.c).angle(); if(sgn(angle) < 0) angle += 2 * PI; long double angleL = angle + PI / 2; long double angleR = angle - PI / 2; if(angleL < 0) angleL += 2 * PI; if(angleR < 0) angleR += 2 * PI; Point PL = A.point(angleL), PR = A.point(angleR), dirL = PL - O, dirR = PR - O; long double disL = O.dis(PL), disrL = R * R / disL, disR = O.dis(PR), disrR = R * R / disR; return Line(O + dirL.trunc(disrL), O + dirR.trunc(disrR)); }
struct Convex : Polygon{ Convex operator +(const Convex &c){ const auto &p = this->p; vector<Line> e1(p.size()), e2(c.p.size()), edge(p.size() + c.p.size()); Convex res; res.p.reserve(p.size() + c.p.size()); for(int i = 0; i < p.size(); i++){ e1[i] = {p[i], p[this -> nxt(i)]}; } for(int i = 0; i < c.p.size(); i++){ e2[i] = {c.p[i], c.p[c.nxt(i)]}; } const auto cmp = [](const Line &u,const Line &v) { return argcmpC(u.e - u.s, v.e - v.s); }; rotate(e1.begin(), min_element(e1.begin(), e1.end(), cmp), e1.end()); rotate(e2.begin(), min_element(e2.begin(), e2.end(), cmp), e2.end()); merge(e1.begin(), e1.end(), e2.begin(), e2.end(), edge.begin(), cmp); const auto check = [](const vector<Point> &p, const Point &u){ const auto back1 = p.back(), back2 = *prev(p.end(), 2); return (back1 - back2).toleft(u - back1) == 0 && (back1 - back2) * (u - back1) >= -eps; }; auto u = e1[0].s + e2[0].s; for(const auto &v : edge){ while(res.p.size() > 1 && check(res.p, u)){ res.p.pop_back(); } res.p.push_back(u); u = u + v.e - v.s; } if(res.p.size() > 1 && check(res.p, res.p[0])) res.p.pop_back(); return res; } int inConvex(const Point &a){ auto &p = this->p; int l = 1, r = (int)(p.size()) - 2; while(l <= r){ auto mid = (l + r) / 2; auto t1 = (p[mid] - p[0]).toleft(a - p[0]); auto t2 = (p[mid + 1] - p[0]).toleft(a - p[0]); if(t1 >= 0 && t2 <= 0){ if(mid == 1 && Line(p[0], p[mid]).isOnSeg(a)) return -1; if(mid + 1 == (int)(p.size()) - 1 && Line(p[0], p[mid + 1]).isOnSeg(a)) return -1; if(Line(p[mid], p[mid + 1]).isOnSeg(a)) return -1; return (p[mid + 1] - p[mid]).toleft(a - p[mid]) > 0; } if(t1 < 0) r = mid - 1; else l = mid + 1; } return false; } template<typename F> void rotcaliper(const F &func) { const auto &p = this->p; const auto area = [](const Point &u, const Point &v, const Point &w){ return fabs((w - u) ^ (w - v)); }; for(int i = 0, j = 1; i < p.size(); i++){ const auto nxti = this -> nxt(i); func(p[i], p[nxti], p[j]); while(area(p[this -> nxt(j)], p[i], p[nxti]) >= area(p[j], p[i], p[nxti])){ j = this -> nxt(j); func(p[i], p[nxti], p[j]); } } } long double diameter2(){ const auto &p = this -> p; if(p.size() == 1) return 0; if(p.size() == 2) return p[0].dis2(p[1]); long double ans = 0; auto func = [&](const Point &u, const Point &v, const Point &w){ ans = max(ans, max(w.dis2(u), w.dis2(v))); }; rotcaliper(func); return ans; } template<typename F> int extreme(const F &dir){ auto &p = this -> p; auto check = [&](const int i){ return dir(p[i]).toleft(p[this->nxt(i)] - p[i]) >= 0; }; auto dir0 = dir(p[0]); auto check0 = check(0); if(check0 == 0 && check((int)(p.size()) - 1)) return 0; int l = 0, r = p.size() - 1; while(l < r){ auto mid = (l + r) / 2; auto checkm = check(mid); if(checkm == check0){ auto t = dir0.toleft(p[mid] - p[0]); if((check0 == 0 && t <= 0) || (check0 && t < 0)) checkm ^= 1; } if(checkm) l = mid + 1; else r = mid; } return r; } pair<int, int> tangent(const Point &a){ int i = extreme([&](const Point &u){ return u - a; }); int j = extreme([&](const Point &u){ return a - u; }); return {i, j}; } pair<int, int> tangent(const Line &l, const Point &dir){ int i = extreme([&](...){ return dir; }); int j = extreme([&](...){ return -dir; }); return {i, j}; } bool isLineCrossConvex(const Line &l, const Point &dir){ if(p.size() <= 1) return true; if(p.size() == 2) return l.toleft(p[0]) == l.toleft(p[1]); auto t = tangent(l, dir); return l.toleft(p[t.first]) == l.toleft(p[t.second]); } };
struct sumConvex : Convex{ vector<long double> sum; void init(){ getSum(); } void getSum(){ auto &p = this->p; vector<long double> a(p.size()); for(int i = 0; i < p.size(); i++){ a[i] = p[this->pre(i)] ^ p[i]; } sum.resize(p.size()); partial_sum(a.begin(), a.end(), sum.begin()); } long double queryTangentSum(const Point &a){ auto &p = this->p; pair<int, int> result = this->tangent(a); int l = result.second, r = result.first; return querySum(l, r); } long double querySum(){ return sum.back(); } long double querySum(int l, int r){ if(l <= r) return sum[r] - sum[l] + (p[r] ^ p[l]); return sum[p.size() - 1] - sum[l] + sum[r] + (p[r] ^ p[l]); } };
struct Halfplane : Line{ Halfplane(){} Halfplane(Point _s, Point _e){s = _s; e = _e;} bool operator <(const Halfplane &b){ Point A = e - s, B = b.e - b.s; return argcmpC(A, B); } };
struct Halfplanes{ int n, st, ed, que[maxn]; Point p[maxn]; Halfplane hp[maxn]; void unique(){ int m = 1; for(int i = 1; i < n; i++){ if(!(sgn(hp[i] ^ hp[i - 1]) == 0 && sgn(hp[i] * hp[i - 1]) >= 0)){ hp[m++] = hp[i]; } else if(sgn((hp[m - 1].e - hp[m - 1].s) ^ (hp[i].s - hp[m - 1].s)) > 0){ hp[m - 1] = hp[i]; } } n = m; } bool Halfplaneinsert(){ sort(hp, hp + n); unique(); que[st = 0] = 0; que[ed = 1] = 1; p[1] = hp[0].crosspoint(hp[1]); for(int i = 2; i < n; i++){ while(st < ed && sgn((hp[i].e - hp[i].s) ^ (p[ed] - hp[i].s)) < 0) ed--; while(st < ed && sgn((hp[i].e - hp[i].s) ^ (p[st + 1] - hp[i].s)) < 0) st++; que[++ed] = i; if(hp[i].parallel(hp[que[ed - 1]])) return false; p[ed] = hp[i].crosspoint(hp[que[ed - 1]]); } while(st < ed && sgn((hp[que[st]].e - hp[que[st]].s) ^ (p[ed] - hp[que[st]].s)) < 0) ed--; while(st < ed && sgn((hp[que[ed]].e - hp[que[ed]].s) ^ (p[st + 1] - hp[que[ed]].s)) < 0) st++; if(st + 1 >= ed) return false; return true; } void getConvex(Polygon &con){ p[st] = hp[que[st]].crosspoint(hp[que[ed]]); for(int j = st, i = 0; j <= ed; i++, j++){ con.p.push_back(p[j]); } } void push(Halfplane tmp){ hp[n++] = tmp; } };
Point DBASIC; bool argcmpB(const Point &A, const Point &B){ Point p1 = A - DBASIC, p2 = B - DBASIC; long double len1 = p1.len2(), len2 = p2.len2(); long double ang1 = p1.angle(), ang2 = p2.angle(); if(sgn(ang1 - ang2) == 0) return len1 < len2; return ang1 < ang2; } struct DConvexHull{ set<Point, decltype(&argcmpB)> Set{&argcmpB}; void init(const Point &A, const Point &B, const Point &C){ DBASIC = {(A.x + B.x + C.x) / 3, (A.y + B.y + C.y) / 3}; Set.insert(A); Set.insert(B); Set.insert(C); } set<Point>::iterator Pre(set<Point>::iterator it){ if(it == Set.begin()) it = Set.end(); return --it; } set<Point>::iterator Nxt(set<Point>::iterator it){ ++it; return it == Set.end() ? Set.begin() : it; } bool Query(Point v){ auto it = Set.lower_bound(v); if(it == Set.end()) it = Set.begin(); Point v1 = v - (*Pre(it)); Point v2 = (*it) - (*Pre(it)); return sgn(v1 ^ v2) <= 0; } void Insert(Point v){ if(Query(v)) return; Set.insert(v); auto it = Nxt(Set.find(v)); while(Set.size() > 3 && sgn((v - (*Nxt(it))) ^ ((*it) - (*Nxt(it)))) <= 0){ Set.erase(it); it = Nxt(Set.find(v)); } it = Pre(Set.find(v)); while(Set.size() > 3 && sgn((v - (*it)) ^ ((*it) - (*Pre(it)))) >= 0){ Set.erase(it); it = Pre(Set.find(v)); } } };
signed main(void){ cout << "Helloworld!\n"; }
|