QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#342210 | #4368. Oil | value0 | AC ✓ | 815ms | 3964kb | C++20 | 6.1kb | 2024-03-01 09:45:01 | 2024-03-01 09:45:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef long long db;
const db EPS = 0;
inline int sign(db a) { return a < -EPS ? -1 : a > EPS; }
inline int cmp(db a, db b) { return sign(a - b); }
struct P
{
db x, y;
P() {}
P(db _x, db _y) : x(_x), y(_y) {}
P operator+(P p) { return {x + p.x, y + p.y}; }
P operator-(P p) { return {x - p.x, y - p.y}; }
P operator*(db d) { return {x * d, y * d}; }
P operator/(db d) { return {x / d, y / d}; }
bool operator<(P p) const
{
int c = cmp(x, p.x);
if (c)
return c == -1;
return cmp(y, p.y) == -1;
}
bool operator==(P o) const
{
return cmp(x, o.x) == 0 && cmp(y, o.y) == 0;
}
db dot(P p) { return x * p.x + y * p.y; }
db det(P p) { return x * p.y - y * p.x; }
db dsitTo(P p) { return (*this - p).abs(); }
db alpha() { return atan2(y, x); }
void read() { cin >> x >> y; }
void write() { cout << "(" << x << "," << y << ")" << endl; }
db abs() { return sqrt(abs2()); }
db abs2() { return x * x + y * y; }
P rot90() { return P(-y, x); }
P unit() { return *this / abs(); }
// 判断点在(0,pi)还是(-pi,0),用于极角排序
int quad() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0); }
P rot(db an) { return {x * cos(an) - y * sin(an), x * sin(an) + y * cos(an)}; }
};
#define cross(p1, p2, p3) ((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y))
#define crossOp(p1, p2, p3) sign(cross(p1, p2, p3))
// 直线p1p2, q1q2 是否恰有一个交点
bool chkLL(P p1, P p2, P q1, P q2)
{
db a1 = cross(q1, q2, p1);
db a2 = -cross(q1, q2, p2);
return sign(a1 + a2) != 0;
}
// 直线p1p2, q1q2 的交点
P isLL(P p1, P p2, P q1, P q2)
{
db a1 = cross(q1, q2, p1);
db a2 = -cross(q1, q2, p2);
return (p1 * a2 + p2 * a1) / (a1 + a2);
}
bool intersect(db l1, db r1, db l2, db r2)
{
if (l1 > r1)
swap(l1, r1);
if (l2 > r2)
swap(l2, r2);
return !(cmp(r1, l2) == -1 || cmp(r2, l1) == -1);
}
// 线段 p1p2, q1q2 相交
bool isSS(P p1, P p2, P q1, P q2)
{
return intersect(p1.x, p2.x, q1.x, q2.x) && intersect(p1.y, p2.y, q1.y, q2.y) &&
crossOp(p1, p2, q1) * crossOp(p1, p2, q2) <= 0 && crossOp(q1, q2, p1) * crossOp(q1, q2, p2) <= 0;
}
// 线段 p1p2, q1q2 严格相交(交点不会在端点)
bool isSS_strict(P p1, P p2, P q1, P q2)
{
return crossOp(p1, p2, q1) * crossOp(p1, p2, q2) < 0 && crossOp(q1, q2, p1) * crossOp(q1, q2, p2) < 0;
}
// m是否在ab上
bool isMiddle(db a, db m, db b)
{
// if (a > b) swap(a, b);
// return cmp(a, m) <= 0 && cmp(m, b) <= 0;
return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}
bool isMiddle(P a, P m, P b)
{
return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
}
// 点 p 在线段 p1p2 上
bool onSeg(P p1, P p2, P q)
{
// crossOp精度问题严重,如果确定q,p1,p2三点共线,那么直接isMiddle判断
return crossOp(p1, p2, q) == 0 && isMiddle(p1, q, p2);
}
// 点 p y严格在线段 p1p2 上
bool onSeg_strict(P p1, P p2, P q)
{
return crossOp(p1, p2, q) == 0 && sign((q - p1).dot(p1 - p2)) * sign((q - p2).dot(p1 - p2)) < 0;
}
// q 在直线 p1p2 上的垂足(投影坐标) 注意:p1 != p2
P proj(P p1, P p2, P q)
{
P dir = p2 - p1;
return p1 + dir * (dir.dot(q - p1) / dir.abs2());
}
// 以 p1p2 为轴 对点 q 进行反射
P reflect(P p1, P p2, P q)
{
return proj(p1, p2, q) * 2 - q;
}
// 求 q 到线段 p1p2 的最小距离
db nearest(P p1, P p2, P q)
{
if (p1 == p2)
return p1.dsitTo(q);
P h = proj(p1, p2, q);
if (isMiddle(p1, h, p2))
return q.dsitTo(h);
return min(p1.dsitTo(q), p2.dsitTo(q));
}
// 求线段 p1p2 与线段 q1q2 的距离
db disSS(P p1, P p2, P q1, P q2)
{
if (isSS(p1, p2, q1, q2))
return 0;
return min(min(nearest(p1, p2, q1), nearest(p1, p2, q2)), min(nearest(q1, q2, p1), nearest(q1, q2, p2)));
}
// 极角排序
// sort(p, p + n, [&]( P &a, P &b)
// { int qa = a.quad(), qb = b.quad();
// if (qa != qb) return qa < qb;
// else return sign(a.det(b)) > 0; });
const int N = 2010;
ll ans;
int n;
P p[N][2];
pair<P, ll> evt[2 * N];
ll solve(P o)
{
int t = 0;
for (int i = 1; i <= n; i++)
{
// 同一y值不看
if (p[i][0].y == o.y)
continue;
// 左端点
P p1 = p[i][0] - o;
// 右端点,极角序一定小于左端点链接出的向量
P p2 = p[i][1] - o;
int len = p[i][1].x - p[i][0].x;
if (p[i][1].y > o.y)
{
// 扫描进入
evt[t++] = {p2, len};
// 扫描退出
evt[t++] = {p1, -len};
}
// 考虑360度的直线旋转,将所有向量转化到一个半区内,这样相当于统计另一个半区时,把射线延长为直线
else
{
// 扫描进入
evt[t++] = {p1 * (-1), len};
// 扫描退出
evt[t++] = {p2 * (-1), -len};
}
}
sort(evt, evt + t, [&](pair<P, ll> &a, pair<P, ll> &b)
{
auto d = a.first.det(b.first);
if (d != 0) return d > 0;
// 卡端点,先加后减
else return a.second > b.second; });
ll res = 0;
ll cur = 0;
for (int i = 0; i < t; i++)
{
cur += evt[i].second;
res = max(res, cur);
}
return res;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int x1, x2, y;
scanf("%d %d %d", &x1, &x2, &y);
if (x1 > x2)
{
swap(x1, x2);
}
p[i][0] = P(x1, y);
p[i][1] = P(x2, y);
}
// 对每个点端点扫描一遍
for (int i = 1; i <= n; i++)
{
// 做的时候不考虑本线段的长度,最后加上
ans = max(ans, max(solve(p[i][0]), solve(p[i][1])) + p[i][1].x - p[i][0].x);
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
input:
5 100 180 20 30 60 30 70 110 40 10 40 50 0 80 70
output:
200
result:
ok single line: '200'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
3 50 60 10 -42 -42 20 25 0 10
output:
25
result:
ok single line: '25'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
1 -100 180 20
output:
280
result:
ok single line: '280'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
1 -1000000 1000000 1
output:
2000000
result:
ok single line: '2000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
1 -1000000 1000000 1000000
output:
2000000
result:
ok single line: '2000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 -1000000 -999999 1000000
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1 1000000 999999 1000000
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
2 -1000 0 200 1 1000 200
output:
1000
result:
ok single line: '1000'
Test #9:
score: 0
Accepted
time: 214ms
memory: 3700kb
input:
1000 737368 429284 959063 -548693 513523 43074 243164 -465669 860567 422975 -244747 588631 -136535 -470055 501433 -580596 -269833 22422 476738 -448258 866889 358773 563858 950905 -923261 208187 66835 -295330 444422 360513 -903435 841952 491761 377801 520064 65247 479135 -307498 426574 -794533 -46924...
output:
490622362
result:
ok single line: '490622362'
Test #10:
score: 0
Accepted
time: 214ms
memory: 3704kb
input:
1000 393505 133958 96751 942939 72421 396439 -822694 -718897 366172 -833366 91559 389785 28456 -507666 398767 -178646 616985 288351 465302 236829 106233 -911686 531549 436738 946908 -619546 27459 840101 -51671 27117 904596 -552691 993402 -379495 -968868 996117 -993434 826061 624577 390359 750548 209...
output:
474626777
result:
ok single line: '474626777'
Test #11:
score: 0
Accepted
time: 213ms
memory: 3700kb
input:
1000 91153 -919136 629430 -928593 -340764 946503 -958781 151370 414466 776584 -865178 350581 266056 -678142 180528 855892 -61597 800115 -150759 821898 16625 286683 401612 387028 -104779 -495288 75284 -292434 725113 64163 925796 -886633 920311 -995416 275385 423913 -922152 395549 705834 138194 618689...
output:
482990936
result:
ok single line: '482990936'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
3 10 20 10 20 30 20 10 20 30
output:
30
result:
ok single line: '30'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3 10 20 30 20 30 20 10 20 10
output:
30
result:
ok single line: '30'
Test #14:
score: 0
Accepted
time: 24ms
memory: 3884kb
input:
1000 -500 -499 3 -499 -498 4 -498 -497 3 -497 -496 4 -496 -495 3 -495 -494 4 -494 -493 3 -493 -492 4 -492 -491 3 -491 -490 4 -490 -489 3 -489 -488 4 -488 -487 3 -487 -486 4 -486 -485 3 -485 -484 4 -484 -483 3 -483 -482 4 -482 -481 3 -481 -480 4 -480 -479 3 -479 -478 4 -478 -477 3 -477 -476 4 -476 -4...
output:
4
result:
ok single line: '4'
Test #15:
score: 0
Accepted
time: 24ms
memory: 3808kb
input:
1000 -500 -499 3 -499 -498 4 -498 -497 3 -497 -496 4 -496 -495 3 -495 -494 4 -494 -493 3 -493 -492 4 -492 -491 3 -491 -490 4 -490 -489 3 -489 -488 4 -488 -487 3 -487 -486 4 -486 -485 3 -485 -484 4 -484 -483 3 -483 -482 4 -482 -481 3 -481 -480 4 -480 -479 3 -479 -478 4 -478 -477 3 -477 -476 4 -476 -4...
output:
4
result:
ok single line: '4'
Test #16:
score: 0
Accepted
time: 50ms
memory: 3724kb
input:
500 885456 935548 893024 644787 -652783 650298 808938 947594 815852 432081 -622268 435774 142740 -169702 143960 856557 925094 863878 261261 -736938 263494 930033 956540 937982 417456 924584 421024 594945 978958 600030 893646 933174 901284 547677 775565 552358 883935 916485 891490 821457 984796 82847...
output:
244491195
result:
ok single line: '244491195'
Test #17:
score: 0
Accepted
time: 38ms
memory: 3724kb
input:
500 45689 45688 429334 -25319 -25320 894329 522056 522055 312322 -235913 -235914 80549 -426659 -426658 805356 411907 411906 645880 426220 426221 921612 -231572 -231571 910658 -875534 -875533 98045 846207 846206 829899 537791 537790 316936 307422 307423 401580 944769 944770 344664 979191 979192 10757...
output:
3
result:
ok single line: '3'
Test #18:
score: 0
Accepted
time: 38ms
memory: 3916kb
input:
500 179265 179266 321892 -979392 -979391 937361 253303 253304 662093 15752 15753 454134 852294 852295 799415 -412075 -412074 216608 727687 727686 146860 -594461 -594460 201360 866097 866096 403699 558297 558298 877893 759626 759627 517730 -409242 -409243 646944 -117540 -117541 298990 -291402 -291401...
output:
3
result:
ok single line: '3'
Test #19:
score: 0
Accepted
time: 38ms
memory: 3948kb
input:
500 93517 93518 342725 -526642 -526641 673580 -677576 -677575 72016 945873 945874 659771 353454 353453 240805 -829016 -829015 865082 164010 164009 830895 560978 560979 311174 -692476 -692477 84711 536284 536283 727900 335375 335374 145312 417370 417369 61814 826406 826407 429567 -958557 -958556 9207...
output:
3
result:
ok single line: '3'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3880kb
input:
1000 -314183 -313894 798067 -425756 -425118 798067 -292017 -290420 798067 -886889 -885538 798067 -467401 -466095 798067 -854994 -854815 798067 -513964 -513655 798067 -738214 -737165 798067 -370302 -370033 798067 -520695 -520311 798067 939776 940229 798067 -507203 -505083 798067 -430399 -430073 79806...
output:
10859
result:
ok single line: '10859'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3932kb
input:
1000 382451 382452 78441 857836 857837 78441 901408 901409 78441 553681 553682 78441 958497 958498 78441 558159 558160 78441 -25805 -25804 78441 -347668 -347667 78441 -273817 -273816 78441 831018 831019 78441 -388683 -388682 78441 133277 133278 78441 687349 687350 78441 -840786 -840785 78441 -928903...
output:
1
result:
ok single line: '1'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
40 -1000000 -999999 1 1000000 999999 1 -1000000 -999999 2 1000000 999999 2 -999997 -999996 3 999997 999996 3 -999991 -999990 4 999991 999990 4 -999979 -999978 5 999979 999978 5 -999955 -999954 6 999955 999954 6 -999907 -999906 7 999907 999906 7 -999811 -999810 8 999811 999810 8 -999619 -999618 9 999...
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 214ms
memory: 3936kb
input:
1000 -562471 -912107 906506 -274879 -684768 698460 -874397 -188848 93604 -28794 -705403 609340 -167399 672073 966800 574383 -905547 886644 -606533 550812 888727 1562 230412 549342 677277 -834070 132706 -449549 540411 221803 73145 952104 336019 829568 -100383 692127 829833 -903703 193961 -174794 -191...
output:
475321294
result:
ok single line: '475321294'
Test #24:
score: 0
Accepted
time: 215ms
memory: 3964kb
input:
1000 535429 -631156 23269 512514 443281 542836 819566 -570924 519963 590031 -433565 264096 923294 160073 940091 -593408 -22399 532315 684799 -775238 49209 147113 -229349 981796 -756171 -526454 792463 206727 -23932 752629 -966010 983032 506651 890735 874240 566955 116980 217648 481666 -256065 621601 ...
output:
520621781
result:
ok single line: '520621781'
Test #25:
score: 0
Accepted
time: 215ms
memory: 3896kb
input:
1000 -539833 289597 151993 -97690 368210 28207 -324216 -553930 596542 -186165 -607098 656556 -66638 955440 205040 395039 329828 131162 226670 -134576 92227 -955914 -406966 866136 92055 -780943 194200 911334 415803 292298 556810 -852515 101714 -343033 992805 225276 -63525 846157 772818 335979 638756 ...
output:
491071907
result:
ok single line: '491071907'
Test #26:
score: 0
Accepted
time: 193ms
memory: 3880kb
input:
1000 -575337 -573660 851311 686087 691270 873892 -638060 -639269 772876 -720300 -722235 245651 716357 725256 738087 488406 490701 246614 -727750 -731177 325662 -991421 -999235 200753 537028 533528 669169 122969 125027 367320 -760777 -756503 49216 246388 237769 474145 -531151 -521821 289201 489068 48...
output:
105038
result:
ok single line: '105038'
Test #27:
score: 0
Accepted
time: 193ms
memory: 3804kb
input:
1000 205431 197003 881149 -864713 -867761 485945 103404 107198 990073 74999 77596 650806 -255915 -253437 874190 744948 749615 48710 815593 825399 598966 191407 193371 814024 701448 692913 225997 -291367 -294844 760471 -28317 -23376 104332 190642 187676 514001 805351 797488 445584 -402481 -408400 532...
output:
109988
result:
ok single line: '109988'
Test #28:
score: 0
Accepted
time: 193ms
memory: 3824kb
input:
1000 -558787 -551785 414529 120708 117367 973219 52208 51253 365345 -817392 -819311 546764 364514 372039 29492 -455925 -458922 588004 723878 733467 500184 977966 972616 688853 -34109 -37970 906557 918076 913630 206217 432948 425377 848473 88518 85204 705668 -254455 -250148 690900 842171 838210 58930...
output:
95852
result:
ok single line: '95852'
Test #29:
score: 0
Accepted
time: 186ms
memory: 3884kb
input:
1000 -157084 -157031 185405 -452796 -452881 463752 591511 591484 977598 523880 523929 61733 476997 477001 518007 -172268 -172276 65342 727194 727244 48770 966693 966690 801748 -223375 -223328 848052 -510495 -510411 126903 461655 461593 227992 411293 411309 931068 -58673 -58621 284529 -90156 -90124 7...
output:
366
result:
ok single line: '366'
Test #30:
score: 0
Accepted
time: 184ms
memory: 3900kb
input:
1000 306232 306284 502945 433479 433417 876592 -210218 -210157 872427 -252484 -252474 757623 -407893 -407815 227373 932894 932800 44474 -871695 -871765 212158 187159 187201 638974 894022 894071 760736 411140 411171 305793 -336595 -336512 231004 383131 383196 518029 -528070 -528079 894547 120550 1206...
output:
322
result:
ok single line: '322'
Test #31:
score: 0
Accepted
time: 185ms
memory: 3880kb
input:
1000 -238925 -238996 224432 -752092 -752047 183057 286146 286090 253260 585403 585354 117949 -20067 -20048 257759 -323288 -323286 945046 -966696 -966599 767354 218085 218065 687818 -134562 -134477 320406 799157 799235 316087 492773 492780 625156 85051 85116 33060 1045 1061 788035 30271 30327 852769 ...
output:
371
result:
ok single line: '371'
Test #32:
score: 0
Accepted
time: 181ms
memory: 3936kb
input:
1000 765193 765193 377744 -784373 -784373 391530 -330706 -330706 475509 349530 349530 887257 -583109 -583109 158120 699638 699638 268352 771899 771899 78706 753056 753056 546394 117356 117356 137367 931180 931180 957933 225981 225981 669848 -62771 -62771 32869 206592 206592 706224 637628 637628 5675...
output:
0
result:
ok single line: '0'
Test #33:
score: 0
Accepted
time: 815ms
memory: 3964kb
input:
2000 -562311 -562310 985766 594472 594473 372479 -178003 -178002 762574 -253391 -253390 553791 -138948 -138947 90598 -97412 -97411 874559 659874 659875 292807 424559 424560 312347 105222 105223 716911 -902757 -902756 11807 411176 411177 673969 342551 342552 650414 -956681 -956680 76972 -194819 -1948...
output:
4
result:
ok single line: '4'
Test #34:
score: 0
Accepted
time: 804ms
memory: 3928kb
input:
2000 -887753 -887752 404724 724046 724047 957791 -703081 -703080 340344 927562 927563 103216 992630 992631 352035 -587464 -587463 966759 -189871 -189870 717462 -155303 -155302 479334 209953 209954 344773 -881275 -881274 476467 -455010 -455009 154987 -61478 -61477 957555 -211119 -211118 15455 858290 ...
output:
8
result:
ok single line: '8'
Test #35:
score: 0
Accepted
time: 811ms
memory: 3964kb
input:
2000 -13398 -13397 651308 438778 438779 106392 -980056 -980055 476576 -971701 -971700 861497 338379 338380 271416 -467547 -467546 287153 -644885 -644884 136944 -81843 -81842 753597 -530265 -530264 429395 -596683 -596682 9812 -287498 -287497 447937 -350707 -350706 253609 -822875 -822874 21630 -947072...
output:
16
result:
ok single line: '16'
Test #36:
score: 0
Accepted
time: 812ms
memory: 3904kb
input:
2000 675859 675860 556169 -584853 -584852 667147 226791 226792 232710 -638320 -638319 444718 -725115 -725114 631591 65948 65949 610220 -2171 -2170 60676 -217210 -217209 497472 274559 274560 637695 -768466 -768465 144682 -717968 -717967 41946 -575055 -575054 426546 944403 944404 21382 346596 346597 9...
output:
28
result:
ok single line: '28'
Test #37:
score: 0
Accepted
time: 155ms
memory: 3740kb
input:
1000 -1000000 1000000 227965 -1000000 1000000 959376 -1000000 1000000 625867 1000000 -1000000 68512 1000000 -1000000 267242 -1000000 1000000 628405 -1000000 1000000 185557 -1000000 1000000 831681 -1000000 1000000 830877 -1000000 1000000 883925 -1000000 1000000 881126 -1000000 1000000 351724 -1000000...
output:
2000000000
result:
ok single line: '2000000000'
Test #38:
score: 0
Accepted
time: 220ms
memory: 3900kb
input:
1000 0 198476 519794 -500000 45298 128787 242746 500000 632799 140298 -1000000 371287 266496 1000000 693424 282570 -1000000 734455 -1000000 146834 387971 -500000 311488 808272 185898 1000000 487687 -500000 263760 686440 286294 -1000000 743961 351464 -1000000 910316 19268 -500000 62342 65666 0 180779...
output:
649382066
result:
ok single line: '649382066'