QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354729#4368. Oiligor_the_creatorAC ✓923ms4056kbC++175.4kb2024-03-15 21:53:432024-03-15 21:53:45

Judging History

你现在查看的是最新测评结果

  • [2024-03-15 21:53:45]
  • 评测
  • 测评结果:AC
  • 用时:923ms
  • 内存:4056kb
  • [2024-03-15 21:53:43]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long db;

const int N = 2e3 + 5;
const int Mod = 998244353;
const int INF = 1e18;
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 { // ?: 0, 1e-9, 2e-9...
		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 distTo(P p) {return (*this - p).abs();}
	db alpha() {return atan2(y, x);} // 范围:[-pai, pai] 
	// 反正切值,极角,long double 用 atan2l() ,三角函数比较慢 
	void read() {cin >> x >> y;}
	void write() {cout << "(" << x << "," << y << ")" << "\n";}
	db abs() {return sqrt(abs2());}
	db abs2() {return x * x + y * y;}
    int quad() const {return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0);}
	// 判断在上半边还是下半边 
	P rot90() {return P{-y, x};} // 逆时针旋转90度
	P unit() {return *this/abs();} // 单位向量 
	P rot(db an) {return {x * cos(an) - y * sin(an), x * sin(an) + y * cos(an)};} 
	// 逆时针转an度, (x+yi)(cos0+sin0i) 
}; 

#define cross(p1, p2, p3) ((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y))
// = p1p2 x p1p3 = (p2 - p1) x (p3 - p1) (叉乘)
#define crossOp(p1, p2, p3) sign(cross(p1, p2, p3)) // 求叉乘符号
// >0 : 三点乘逆时针, =0:三点共线,<0:顺时针 

bool chkLL(P p1, P p2, P q1, P q2) // 直线p、q是否恰有一个交点 
{
	db s1 = cross(q1, q2, p1), s2 = -cross(q1, q2, p2);
	return sign(s1 + s2) != 0; 
}

P isLL(P p1, P p2, P q1, P q2) // 求出两条直线的交点 
{
	db s1 = cross(q1, q2, p1), s2 = -cross(q1, q2, p2);
	return (p1 * s2 + p2 * s1) / (s1 + s2);
} 

bool intersect(db l1, db r1, db l2, db r2) // 判断区间[l1,r1]和[l2,r2]是否相交 
{
	if (l1 > r1) swap(l1, r1); if (l2 > r2) swap(l2, r2);
	return !(cmp(r1, l2) == -1 || cmp(r2, l1) == -1);
}

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;
}

bool isSS_strict(P p1, P p2, P q1, P q2) // 线段严格相交('x'只有一个公共点且不是端点) 
{
	return crossOp(p1, p2, q1) * crossOp(p1, p2, q2) < 0 && crossOp(q1, q2, p1) * crossOp(q1, q2, p2) < 0; 
}

bool isMiddle(db a, db m, db b) // m是否在ab之间 
{
	return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}

bool isMiddle(P a, P m, P b) // 点m是否在ab之间 
{
	return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
} 

bool onSeg(P p1, P p2, P q) // 点q是否在线段p1p2上 
{
	return crossOp(p1, p2, q) == 0 && isMiddle(p1, q, p2);
	// crossOp容易有精度问题...  
}

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;
} 

P proj(P p1, P p2, P q) // 求q到直线p1p2的投影(垂足) attention: p1!=p2
{
	P dir = p2 - p1;
	return p1 + dir * (dir.dot(q - p1) / dir.abs2());
} 

P reflect(P p1, P p2, P q) // 求q以p1p2为轴的反射 
{
	return proj(p1, p2, q) * 2ll - q;
}

db nearest(P p1, P p2, P q) // 求q到p1p2的最小距离 
{
	if (p1 == p2) return p1.distTo(q);
	P h = proj(p1, p2, q);
	if (isMiddle(p1, h, p2)) return q.distTo(h);
	return min(p1.distTo(q), p2.distTo(q));
}

db disSS(P p1, P p2, P q1, P q2) // 求两条线段的距离 
{
	if (isSS(p1, p2, q1, q2)) return 0;
	return min({nearest(p1, p2, q1), nearest(p1, p2, q2), nearest(q1, q2, p1), nearest(q1, q2, p2)}); 
}

int n;

struct L{
	P l, r;
	int w;
}d[N];

int work(P p)
{
	vector<pair<P, int>> cnt;
	for (int i = 1; i <= n; ++i) {
		if (d[i].l.y == p.y) continue;
		P p1 = d[i].l - p, p2 = d[i].r - p;
		if (d[i].l.y > p.y) {
			cnt.pb({p1, -d[i].w});
			cnt.pb({p2, d[i].w});
		}
		else {
			cnt.pb({p1 * (-1), d[i].w});
			cnt.pb({p2 * (-1), -d[i].w});
		}
	}
	sort(cnt.begin(), cnt.end(), [&](pair<P, int> &a, pair<P, int> &b) {
		db q = a.fi.det(b.fi);
		if (q != 0) return q > 0;
		return a.se > b.se;
	});
	int ans = 0, now = 0;
	for (auto i: cnt) {
		now += i.se;
		ans = max(ans, now);
	}
	return ans;
}

void solve()
{
	int xl, xr, y;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> xl >> xr >> y;
		if (xl > xr) swap(xl, xr);
		d[i].l = P(xl, y);
		d[i].r = P(xr, y);
		d[i].w = xr - xl;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max({ans, work(d[i].l) + d[i].w, work(d[i].r) + d[i].w});
	cout << ans << "\n";
}

signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1;
//	cin >> t;
	while (t--)
		  solve();
	return 0;
}
/*
5
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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: 3616kb

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: 3836kb

input:

1
-100 180 20

output:

280

result:

ok single line: '280'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

1
-1000000 1000000 1

output:

2000000

result:

ok single line: '2000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3796kb

input:

1
-1000000 1000000 1000000

output:

2000000

result:

ok single line: '2000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

1
-1000000 -999999 1000000

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

1
1000000 999999 1000000

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2
-1000 0 200
1 1000 200

output:

1000

result:

ok single line: '1000'

Test #9:

score: 0
Accepted
time: 232ms
memory: 3696kb

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: 244ms
memory: 3932kb

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: 227ms
memory: 3688kb

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: 1ms
memory: 3604kb

input:

3
10 20 10
20 30 20
10 20 30

output:

30

result:

ok single line: '30'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

3
10 20 30
20 30 20
10 20 10

output:

30

result:

ok single line: '30'

Test #14:

score: 0
Accepted
time: 83ms
memory: 3756kb

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: 77ms
memory: 3928kb

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: 54ms
memory: 3848kb

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: 44ms
memory: 3696kb

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: 42ms
memory: 3680kb

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: 40ms
memory: 3716kb

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: 3688kb

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: 3688kb

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: 3624kb

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: 229ms
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: 231ms
memory: 3984kb

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: 229ms
memory: 3692kb

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: 221ms
memory: 3680kb

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: 211ms
memory: 3756kb

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: 209ms
memory: 3936kb

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: 203ms
memory: 3912kb

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: 205ms
memory: 3752kb

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: 197ms
memory: 3968kb

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: 200ms
memory: 3764kb

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: 923ms
memory: 4056kb

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: 917ms
memory: 3808kb

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: 904ms
memory: 3804kb

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: 893ms
memory: 3848kb

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: 168ms
memory: 3712kb

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: 246ms
memory: 3760kb

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'