QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609008#1223. 回家路线SimonLJK100 ✓52ms11256kbC++142.1kb2024-10-04 10:13:462024-10-04 10:13:47

Judging History

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

  • [2024-10-04 10:13:47]
  • 评测
  • 测评结果:100
  • 用时:52ms
  • 内存:11256kb
  • [2024-10-04 10:13:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+99,M=2e5+99,lim=1000;
int n,m;
ll a,b,c;
ll f(ll x){
	return a*x*x+b*x+c;
}
struct route{
	int x,y,p,q;
	bool operator <(const route&A) const{
		return p<A.p;
	}
}r[M];
struct node{
	int tim,l,r;
	ll val;
};
struct Node{
	int id,tim;
	ll val;
	bool operator <(const Node&A) const{
		return tim>A.tim;
	}
};
vector<node> que[N];
int hh[N],tt[N];
void update(int x,int tim,ll val){
	while(tt[x]>=hh[x]){
		if(que[x][tt[x]].l>=tim&&que[x][tt[x]].val+f(que[x][tt[x]].l-que[x][tt[x]].tim)>=val+f(que[x][tt[x]].l-tim)){
			tt[x]--; que[x].pop_back(); continue;
		}
		else if(que[x][tt[x]].r<tim||(que[x][tt[x]].val+f(que[x][tt[x]].r-que[x][tt[x]].tim)<val+f(que[x][tt[x]].r-tim)))
			break;
		int l=max(que[x][tt[x]].l+1,tim),r=que[x][tt[x]].r,mid; int re=l-1;
		while(l<=r){
			mid=(l+r>>1);
			if(que[x][tt[x]].val+f(mid-que[x][tt[x]].tim)<val+f(mid-tim)) re=mid,l=mid+1;
			else r=mid-1;
		}
		que[x][tt[x]].r=re;
		break;
	}
	if(tt[x]<hh[x]){
		++tt[x];
		que[x].push_back((node){tim,tim,lim,val});
	}
	else if(que[x][tt[x]].r!=lim){
		++tt[x];
		que[x].push_back((node){tim,que[x][tt[x]-1].r+1,lim,val}); 
	}
	return;
}
void upd(int x,int tim){
	while(hh[x]<=tt[x]){
		if(que[x][hh[x]].r<tim) hh[x]++;
		else{
			que[x][hh[x]].l=max(que[x][hh[x]].l,tim);
			break;
		}
	}
	return;
}
int main(){
//	freopen("route.in","r",stdin);
//	freopen("route.out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>a>>b>>c;
	for(int i=1;i<=m;i++)
		cin>>r[i].x>>r[i].y>>r[i].p>>r[i].q;
	sort(r+1,r+m+1);
	que[1].push_back((node){0,0,lim,0}); tt[1]=0;
	for(int i=2;i<=n;i++) tt[i]=-1;
	priority_queue<Node> pq; Node now;
	int x,y,p,q; ll nval,ans=1e17;
	for(int i=1;i<=m;i++){
		x=r[i].x; y=r[i].y; p=r[i].p; q=r[i].q;
		while(!pq.empty()&&pq.top().tim<=p){
			now=pq.top(); pq.pop();
			update(now.id,now.tim,now.val);
		}
		upd(x,p);
		if(hh[x]>tt[x]) continue;
		nval=que[x][hh[x]].val+f(p-que[x][hh[x]].tim);
		if(y==n) ans=min(ans,nval+q);
		else pq.push((Node){y,q,nval});
	}
	cout<<ans;
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 1ms
memory: 6244kb

input:

100 99 10 20 20
76 77 383 384
55 56 282 284
89 90 445 449
45 46 232 235
88 89 439 443
30 31 159 160
97 98 488 492
52 53 267 270
37 38 188 191
61 62 305 306
64 65 322 324
18 19 102 104
47 48 238 239
96 97 484 486
70 71 352 356
65 66 328 330
33 34 171 172
5 6 26 28
22 23 122 124
91 92 458 459
28 29 15...

output:

15254

result:

ok single line: '15254'

Test #2:

score: 5
Accepted
time: 1ms
memory: 6504kb

input:

100 99 10 20 20
41 42 189 192
76 77 340 341
30 31 136 139
78 79 348 349
38 39 173 176
8 9 33 37
16 17 74 78
62 63 283 284
18 19 85 89
66 67 298 302
75 76 335 336
27 28 123 124
64 65 290 291
4 5 16 17
13 14 58 61
57 58 257 259
91 92 420 422
80 81 358 362
53 54 245 246
19 20 93 94
63 64 287 288
37 38 ...

output:

13624

result:

ok single line: '13624'

Test #3:

score: 5
Accepted
time: 2ms
memory: 7704kb

input:

65 92 0 0 0
42 43 222 224
40 41 210 214
1 2 3 6
43 44 227 229
55 56 291 294
34 35 179 183
5 6 26 28
45 46 237 240
23 24 125 126
35 36 184 185
6 7 32 34
44 45 92 328
53 54 282 285
28 29 148 150
25 26 163 181
41 42 41 392
16 17 91 95
27 28 145 146
52 53 148 173
57 58 303 306
26 27 138 141
38 39 200 20...

output:

344

result:

ok single line: '344'

Test #4:

score: 5
Accepted
time: 1ms
memory: 7712kb

input:

63 91 0 0 0
60 61 292 295
9 10 68 544
45 46 220 222
14 15 66 67
8 9 42 46
53 54 258 261
34 35 168 172
37 38 465 705
48 49 342 359
22 23 105 108
18 19 126 294
20 21 95 98
50 51 241 245
48 49 231 233
40 41 196 200
18 19 83 87
42 43 208 209
48 49 22 201
26 27 568 813
56 57 581 675
49 50 234 238
51 52 1...

output:

306

result:

ok single line: '306'

Test #5:

score: 5
Accepted
time: 2ms
memory: 7736kb

input:

1997 3999 0 0 0
958 1350 528 818
235 958 222 396
672 851 435 495
871 958 483 684
958 1141 482 580
780 1110 90 182
940 1047 459 528
1482 1746 397 624
958 1594 7 294
958 1127 540 639
958 1683 277 339
928 958 173 217
392 814 438 684
610 993 556 844
5 1040 572 648
514 1095 74 333
165 827 425 569
1300 15...

output:

455

result:

ok single line: '455'

Test #6:

score: 5
Accepted
time: 0ms
memory: 7744kb

input:

1995 3997 0 0 0
228 1201 94 344
155 228 166 214
1131 1721 536 809
261 856 428 608
228 339 180 246
228 877 536 766
170 981 493 615
228 1012 587 882
228 705 542 612
780 1960 561 797
228 551 110 196
230 442 83 379
44 228 571 864
228 1120 261 422
162 206 255 487
147 228 307 478
228 253 167 292
70 228 48...

output:

444

result:

ok single line: '444'

Test #7:

score: 5
Accepted
time: 2ms
memory: 7928kb

input:

1995 3996 0 0 0
277 717 1 27
717 935 431 460
717 1661 483 763
73 717 479 653
273 717 394 408
717 1521 490 542
717 1572 340 601
717 1260 369 606
712 717 518 700
253 717 74 117
717 1356 535 737
717 1977 376 425
717 1815 128 131
717 977 493 622
448 717 195 261
45 717 46 223
92 717 262 422
111 717 108 3...

output:

333

result:

ok single line: '333'

Test #8:

score: 5
Accepted
time: 2ms
memory: 6264kb

input:

2000 3997 0 0 0
299 1998 585 809
299 1684 222 400
54 299 512 733
299 543 152 429
437 881 254 338
275 299 110 407
299 1833 598 860
299 870 589 702
299 1970 434 638
299 1971 538 552
1831 1969 377 660
299 1555 208 349
1062 1699 39 227
827 1035 43 257
299 826 399 681
299 1071 207 482
22 299 598 761
49 2...

output:

313

result:

ok single line: '313'

Test #9:

score: 5
Accepted
time: 0ms
memory: 8092kb

input:

1993 3992 0 0 991276
617 1724 529 816
439 617 496 784
617 1731 533 668
520 602 483 726
617 1723 549 675
617 747 173 357
489 617 257 315
617 894 315 512
192 617 197 212
75 617 581 834
714 960 11 24
617 1977 511 651
617 1464 197 472
617 1622 333 615
419 617 433 715
211 1306 492 641
617 1600 224 409
61...

output:

4956875

result:

ok single line: '4956875'

Test #10:

score: 5
Accepted
time: 2ms
memory: 6188kb

input:

1992 3998 0 126286 789
197 839 321 529
152 869 178 428
6 1369 461 489
152 900 344 514
152 1956 588 755
152 624 220 246
152 1643 174 364
152 860 412 564
505 1849 371 500
152 1557 543 693
152 975 398 638
145 1259 232 313
152 1804 64 247
152 1817 215 361
152 1648 386 523
296 1664 163 403
152 969 474 75...

output:

31713286

result:

ok single line: '31713286'

Test #11:

score: 5
Accepted
time: 0ms
memory: 7852kb

input:

1998 3999 9 195192 695724
291 932 510 676
77 258 128 172
666 1761 320 580
258 1723 387 415
771 258 385 547
258 605 544 819
258 509 44 114
158 258 533 625
82 258 244 329
258 1014 596 722
1840 258 477 747
24 1809 164 279
909 1814 446 715
1729 258 480 598
477 258 474 518
1730 258 290 587
258 230 270 37...

output:

54237583

result:

ok single line: '54237583'

Test #12:

score: 5
Accepted
time: 2ms
memory: 6336kb

input:

1999 3992 3 704181 281205
793 818 466 545
793 1751 87 343
866 421 591 642
793 1690 239 470
1128 793 18 150
887 793 541 561
1208 1269 591 888
793 1301 386 621
793 886 552 731
1176 485 440 508
1691 793 586 845
793 677 528 555
793 1721 455 462
793 292 151 333
240 793 88 296
230 140 230 422
183 793 504 ...

output:

176471040

result:

ok single line: '176471040'

Test #13:

score: 5
Accepted
time: 2ms
memory: 7724kb

input:

1998 3997 8 445185 553127
484 959 226 291
1443 1342 137 153
277 484 375 655
666 477 535 826
1308 484 311 427
1357 484 280 557
484 1201 169 324
484 665 244 285
595 484 465 610
350 484 445 472
1917 484 309 336
1580 484 99 131
625 97 282 385
1676 1211 542 721
1068 1352 436 513
484 259 438 694
1994 484 ...

output:

61934608

result:

ok single line: '61934608'

Test #14:

score: 5
Accepted
time: 2ms
memory: 7728kb

input:

1998 3995 6 89962 114141
854 400 306 531
183 931 303 413
55 795 587 613
183 297 251 291
1107 1624 79 138
1260 1388 481 550
183 1896 492 517
636 119 97 266
785 1251 261 536
148 183 301 329
805 819 333 482
1659 183 234 454
183 1291 351 536
183 543 136 342
1570 1254 266 395
619 183 283 314
183 1289 39 ...

output:

21318909

result:

ok single line: '21318909'

Test #15:

score: 5
Accepted
time: 48ms
memory: 10576kb

input:

99991 199997 0 0 445689
58135 44290 583 741
15649 34882 476 692
4521 77653 63 189
34882 41463 242 372
34882 67211 40 182
50489 34882 3 288
53538 34882 176 338
43472 74546 502 536
34882 10030 255 472
99621 6833 244 268
98831 34882 339 562
34882 73959 280 350
14793 94088 74 267
34882 33910 90 142
3488...

output:

4011841

result:

ok single line: '4011841'

Test #16:

score: 5
Accepted
time: 46ms
memory: 10732kb

input:

99998 199991 0 502052 86996
91408 32290 467 736
24164 57240 312 441
34091 89736 212 220
32290 9534 233 332
32290 19918 430 547
41271 16413 427 575
83513 32290 374 488
60638 75311 304 336
32290 37792 244 314
20194 92613 56 112
10512 71970 433 537
72798 29751 325 412
72108 87484 467 624
32841 26892 52...

output:

95537061

result:

ok single line: '95537061'

Test #17:

score: 5
Accepted
time: 43ms
memory: 9988kb

input:

99996 200000 0 479823 169059
972 75606 282 293
48452 972 416 490
69769 23165 30 130
972 35331 335 386
82041 972 29 201
972 2296 88 304
972 20438 405 612
55984 972 98 143
972 17312 346 390
70642 972 297 380
41441 972 46 171
972 17251 206 368
64605 70614 210 502
36995 972 423 519
972 74619 580 835
972...

output:

112612205

result:

ok single line: '112612205'

Test #18:

score: 5
Accepted
time: 41ms
memory: 9588kb

input:

99994 199992 2 189886 420942
32552 47075 229 283
58047 15923 595 767
7065 59488 309 331
38326 27625 336 537
87704 47075 227 304
7919 47075 194 444
73088 27237 7 86
84449 47075 392 487
47075 9130 55 200
47075 34270 197 315
24612 47075 111 369
90105 47075 89 266
18796 29906 36 122
93283 71954 256 262
...

output:

53959418

result:

ok single line: '53959418'

Test #19:

score: 5
Accepted
time: 52ms
memory: 11256kb

input:

99994 199998 4 52561 167614
8936 91339 294 452
41369 59827 286 334
17840 89432 177 368
54519 56968 257 294
17840 40642 350 640
78318 17840 322 568
88051 80462 144 371
82083 17840 201 342
80731 25571 229 445
49121 17840 90 274
17840 78652 501 649
2942 17840 331 425
17840 36436 499 555
30164 17840 202...

output:

3512698

result:

ok single line: '3512698'

Test #20:

score: 5
Accepted
time: 39ms
memory: 9824kb

input:

99996 199994 3 267528 901678
7679 23074 513 759
7679 41064 119 318
30805 7679 164 249
93360 194 512 741
52101 55440 335 357
15093 7679 142 245
7679 68585 384 615
20686 17946 412 459
75694 69169 599 714
7679 44664 24 55
28859 84551 177 424
2026 80299 556 612
62381 31544 323 415
16601 94564 466 664
87...

output:

83491868

result:

ok single line: '83491868'

Extra Test:

score: 0
Extra Test Passed