QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#460874#5036. 卑鄙的下毒人Kevin530720 148ms57184kbC++232.7kb2024-07-02 12:26:352024-07-02 12:26:36

Judging History

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

  • [2024-07-02 12:26:36]
  • 评测
  • 测评结果:20
  • 用时:148ms
  • 内存:57184kb
  • [2024-07-02 12:26:35]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) greverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n;
int l[500500],r[500500];
ll w[500500];
ll dp[500500];
int lst[500500];
int choose[500500];
ll dist[500500];
int inque[500500];
vector<pair<int,ll>> G[500500];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	cin>>n>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>l[i]>>r[i]>>w[i];
	vector<pii> vec;
	for(int i=1;i<=n;i++)
		vec.pb(l[i],i);
	srt(vec);
	int p=0;
	memset(dp,-inf,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<=500000;i++)
	{
		if(dp[i]>dp[i+1])
		{
			dp[i+1]=dp[i];
			lst[i+1]=-1;
		}
		while(p<sz(vec)&&vec[p].first==i+1)
		{
			if(dp[i]+w[vec[p].second]>dp[r[vec[p].second]])
			{
				dp[r[vec[p].second]]=dp[i]+w[vec[p].second];
				lst[r[vec[p].second]]=vec[p].second;
			}
			p++;
		}
	}
	ll ans=dp[500000];
	int cur=500000;
	while(cur)
	{
		if(lst[cur]==-1)
		{
			G[cur].pb(cur-1,0);
			cur--;
		}
		else
		{
			choose[lst[cur]]=1;
			cur=l[lst[cur]]-1;
		}
	}
	for(int i=2;i<=k;i++)
	{
		memset(dist,-inf,sizeof(dist));
		priority_queue<pair<ll,int>> pq;
		pq.emplace(0,0);
		dist[0]=0;
		for(int i=1;i<=500000;i++)
			G[i-1].pb(i,0);
		for(int i=1;i<=n;i++)
			if(!choose[i])
				G[l[i]-1].pb(r[i],i);
			else
				G[r[i]].pb(l[i]-1,i);
		while(!pq.empty())
		{
			ll d=pq.top().first;
			int x=pq.top().second;
			pq.pop();
			if(dist[x]!=d) continue;
			for(auto pr:G[x])
			{
				ll edge;
				if(!pr.second) edge=0;
				else if(choose[pr.second]) edge=-w[pr.second];
				else edge=w[pr.second];
				ll nd=edge+dp[x]-dp[pr.first]+dist[x];
				if(nd>dist[pr.first])
				{
					lst[pr.first]=pr.second;
					dist[pr.first]=nd;
					pq.emplace(nd,pr.first);
				}
			}
		}
		for(int i=0;i<=500000;i++)
			G[i].clear();
		int nd=500000;
		while(nd)
		{
			int val=lst[nd];
			if(val)
			{
				nd=l[val]+r[val]-1-nd;
				choose[val]^=1;
			}
			else
				nd--;
		}
		for(int i=0;i<=500000;i++)
			dp[i]=max(dp[i]+dist[i],-1ll*inf*inf);
		ans+=dp[500000]-dp[0]+dist[500000];
	}
	cout<<ans<<endl;
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 67ms
memory: 57184kb

input:

7 20 5
3 4 1
1 1 1
2 7 1
3 7 1
2 2 1
3 7 1
4 6 1
7 7 1
5 5 1
1 6 1
3 4 1
1 4 1
3 6 1
3 3 1
2 5 1
1 1 1
5 5 1
1 1 1
6 7 1
2 2 1

output:

11

result:

wrong answer 1st words differ - expected: '15', found: '11'

Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

1794 5000 5
419 430 46802829
1071 1140 167141363
1154 1554 366136993
735 1265 152210166
387 1104 646459531
1073 1637 525871859
1340 1729 44303243
1221 1574 588158235
91 478 922877048
1117 1268 460323230
315 1103 378106915
272 1071 784282054
1147 1469 220209516
281 375 514585737
677 1031 231082599
55...

output:


result:


Subtask #3:

score: 20
Accepted

Test #31:

score: 20
Accepted
time: 134ms
memory: 41564kb

input:

322675 500000 1
162058 177924 125740423
72321 188693 51206015
73706 159883 238256306
223634 241332 292316893
8164 94217 879196279
232892 319246 624760769
67688 195525 319652781
70831 92026 394982900
68675 156743 598333126
107804 308096 843245966
57077 248406 291662171
12794 193657 560389007
105560 2...

output:

480886198651

result:

ok "480886198651"

Test #32:

score: 0
Accepted
time: 128ms
memory: 43596kb

input:

252531 500000 1
73336 89104 198033994
117801 178724 312536059
83164 115804 819989513
1359 145774 511306394
47527 143191 383786500
1003 48236 76011634
125645 183182 48474946
106010 149967 927727206
103952 112384 125439208
104139 173611 971831922
92285 136188 923537157
1086 180210 427446035
23210 2210...

output:

475010855091

result:

ok "475010855091"

Test #33:

score: 0
Accepted
time: 125ms
memory: 45176kb

input:

249992 490700 1
214479 214496 515365625
14206 14382 334019307
217230 217309 735689827
63924 63925 258401277
12070 12079 934649204
207338 207371 758583044
37166 37413 417324175
126526 126539 124700076
55914 56166 936572436
216053 216093 893982405
45801 46192 131912638
241657 241696 730127825
116589 1...

output:

24050495775217

result:

ok "24050495775217"

Test #34:

score: 0
Accepted
time: 148ms
memory: 45580kb

input:

249997 494845 1
85695 85706 947011452
173987 175115 969606646
50884 50893 735552086
44292 44297 627665457
215893 215931 539749179
110666 111348 593653974
37171 38363 554044675
152491 152726 857012755
128775 129900 279287672
171922 172278 447261487
123925 123930 105674353
54822 54901 583760389
133139...

output:

18391590923314

result:

ok "18391590923314"

Test #35:

score: 0
Accepted
time: 133ms
memory: 46872kb

input:

249935 497717 1
48307 48437 56342637
151763 152298 861912241
19415 19415 927311192
59828 60101 204305982
147582 147862 395948999
186343 186386 10643541
44713 44853 524618914
192169 192211 648592572
188253 188338 998141500
34052 34721 466660212
156785 156916 59576841
202401 202629 971241453
139207 13...

output:

12964165809186

result:

ok "12964165809186"

Test #36:

score: 0
Accepted
time: 143ms
memory: 46220kb

input:

249950 496942 1
62391 62983 157267127
207325 208422 715495951
29165 29192 834359395
91599 91615 332629666
84504 85813 5574214
55544 55732 893133907
68164 68179 848654383
229512 230081 808984107
165586 165713 454872244
200207 201999 968200081
65750 65806 299499692
202042 202614 558169368
140195 14188...

output:

14606631340114

result:

ok "14606631340114"

Test #37:

score: 0
Accepted
time: 136ms
memory: 44924kb

input:

249982 495670 1
86390 86526 783248482
9407 9411 540434263
238452 238534 830682740
91200 91302 364033820
145244 147442 35874704
21309 21354 781112886
220232 221381 997542261
99464 99511 240733162
20848 21196 714567934
164306 164325 993562838
151641 151665 555186611
95172 95199 763915769
189851 189962...

output:

16988476067185

result:

ok "16988476067185"

Test #38:

score: 0
Accepted
time: 127ms
memory: 44636kb

input:

237809 500000 1
1 1 725340623
2 2 556538685
2 3 750113351
2 4 89997667
1 5 176278822
6 6 628044473
4 7 376781143
4 8 691054257
8 9 681694326
8 10 107877180
10 11 895699579
8 12 309610008
9 13 583966770
11 14 91473484
15 15 795666681
14 16 199439006
17 17 235804033
18 18 459166246
15 19 261822162
19 ...

output:

54827431453285

result:

ok "54827431453285"

Test #39:

score: 0
Accepted
time: 129ms
memory: 45724kb

input:

193004 500000 1
1 1 418968490
1 2 696290526
1 3 35413858
2 4 468838187
1 5 249430274
3 6 574413613
4 7 399467033
6 8 75065642
6 9 340727930
6 10 862056055
7 11 902270161
11 12 246578995
12 13 245100768
14 14 911540131
13 15 88554299
13 16 454499535
13 17 232059626
16 18 908692431
15 19 139531524
20 ...

output:

44183387167347

result:

ok "44183387167347"

Test #40:

score: 0
Accepted
time: 127ms
memory: 46400kb

input:

168037 500000 1
1 1 571104806
2 2 127213141
2 3 975939427
3 4 132217350
5 5 894810748
3 6 490775217
4 7 25203836
6 8 458117768
6 9 426044363
8 10 745181289
9 11 432989435
10 12 578165354
9 13 68938921
12 14 793934534
11 15 74005157
16 16 311972043
14 17 625329955
18 18 168234200
15 19 465554170
18 2...

output:

38680733724403

result:

ok "38680733724403"

Test #41:

score: 0
Accepted
time: 115ms
memory: 46280kb

input:

177842 500000 1
1 1 421267539
2 2 773838708
3 3 174145748
2 4 345791748
4 5 178857721
6 6 63445539
5 7 785501019
6 8 293135367
7 9 107408904
6 10 781833072
7 11 380579169
11 12 149601052
13 13 941321725
13 14 68117336
14 15 878597414
14 16 501204638
15 17 856015182
14 18 474203866
18 19 851148153
16...

output:

40928382637201

result:

ok "40928382637201"

Test #42:

score: 0
Accepted
time: 123ms
memory: 46032kb

input:

177915 500000 1
1 1 271292280
2 2 625813925
1 3 939340374
2 4 84776571
5 5 456945542
3 6 191363078
7 7 78237995
4 8 723718315
6 9 199913337
7 10 276964318
11 11 475214330
11 12 956526724
9 13 234753935
11 14 850526973
13 15 377635279
12 16 866464127
16 17 72950802
17 18 54563404
15 19 532673622
20 2...

output:

40869789096961

result:

ok "40869789096961"

Test #43:

score: 0
Accepted
time: 139ms
memory: 43328kb

input:

278352 500000 1
170913 214543 168974049
78160 236308 127212570
22624 192783 758327554
33353 119675 112500515
123238 138960 773944493
102641 104678 525298818
39746 265269 231933608
101566 199878 496386445
160697 214573 875085547
138890 189675 304621779
72230 233413 82446355
93697 111582 716259833
248...

output:

470663510567

result:

ok "470663510567"

Test #44:

score: 0
Accepted
time: 129ms
memory: 43868kb

input:

313114 500000 1
192852 245567 319309601
97135 304118 787617405
76891 190936 17692495
9880 226269 747702459
117760 188046 398275162
61120 289318 158491038
41844 216947 23254041
48629 302643 629285602
262794 301320 933483522
23187 211531 218319925
31448 106981 97268677
32372 191357 161506602
87160 272...

output:

469269376470

result:

ok "469269376470"

Test #45:

score: 0
Accepted
time: 123ms
memory: 47416kb

input:

205945 500000 1
146039 176990 894969853
61417 89219 764910645
37405 123868 427213499
64826 75839 220017382
85594 128873 116882220
186391 190027 882212569
5498 54259 155371726
21164 123514 490637163
96788 187848 376113236
35647 185488 993192042
36184 39246 792947747
108807 165538 393657269
83958 1120...

output:

483741106377

result:

ok "483741106377"

Test #46:

score: 0
Accepted
time: 138ms
memory: 41368kb

input:

500000 500000 1
496837 496870 923496382
278362 278392 357421464
274060 274061 345429203
65297 65317 503103187
236352 236398 120593170
181125 181172 197502113
123694 123736 224553449
130956 130974 786534231
134569 134606 55741322
12360 12365 286706634
300281 300328 410270588
236167 236193 832854993
4...

output:

33887394129829

result:

ok "33887394129829"

Test #47:

score: 0
Accepted
time: 128ms
memory: 39768kb

input:

500000 500000 1
51275 51298 906550332
91442 91490 890797911
483126 483169 880126619
438390 438400 604056812
23577 23608 201153018
112465 112503 146011563
84539 84565 351378223
60262 60277 458827584
305983 306004 140042073
312033 312044 18883706
238027 238047 356335074
163624 163668 134261442
272969 ...

output:

33962870370969

result:

ok "33962870370969"

Test #48:

score: 0
Accepted
time: 120ms
memory: 40168kb

input:

500000 500000 1
57535 57553 874794489
443359 443368 328379248
73189 73203 567826431
200304 200308 552526649
271876 271909 231476665
378433 378453 495669857
108553 108584 431003982
42176 42197 773752461
93371 93401 797605414
404017 404032 25578235
361930 361979 209265
247150 247182 620036262
18378 18...

output:

33917735271253

result:

ok "33917735271253"

Test #49:

score: 0
Accepted
time: 137ms
memory: 41132kb

input:

500000 500000 1
330583 330583 819334510
342192 342225 251008140
23558 23562 693668995
7713 7745 20457747
358117 358150 397036939
484167 484203 505239528
314640 314645 449883400
40462 40503 485953240
77808 77832 572898847
147529 147564 337988142
189570 189614 949484749
453228 453254 752514208
364749 ...

output:

33900595789167

result:

ok "33900595789167"

Test #50:

score: 0
Accepted
time: 123ms
memory: 41284kb

input:

500000 500000 1
167444 167450 930275075
359867 359876 53239020
441544 441576 585496181
439743 439786 17684411
36167 36203 217051650
29078 29096 949040506
124064 124110 880111173
59505 59551 825248135
177726 177746 769432518
17759 17804 604866783
265114 265151 657157449
356894 356929 496106508
82971 ...

output:

33861714821089

result:

ok "33861714821089"

Subtask #4:

score: 0
Time Limit Exceeded

Test #51:

score: 0
Time Limit Exceeded

input:

194181 500000 5
22921 38709 1
103611 130117 1
33044 135246 1
25161 106036 1
13484 183424 1
129622 133239 1
103905 105727 1
8418 141108 1
5951 145648 1
61392 105830 1
139975 149309 1
47361 59947 1
91598 172246 1
32303 43094 1
72490 170121 1
68502 168603 1
56051 91019 1
106112 129606 1
70776 177996 1
...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #66:

score: 0
Time Limit Exceeded

input:

265199 500000 5
51732 151507 196279569
1147 251097 325871693
79410 120618 539045634
209514 221950 912376813
44813 147573 616444800
53619 134328 533306546
94940 108466 186490362
42483 236958 489649490
127349 167018 943263893
103970 193784 202963780
197001 221033 210521750
5815 113674 152090319
129972...

output:


result: