QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639187#7905. Ticket to Ridelsj2009TL 226ms4156kbC++232.4kb2024-10-13 18:13:202024-10-13 18:13:25

Judging History

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

  • [2024-10-13 18:13:25]
  • 评测
  • 测评结果:TL
  • 用时:226ms
  • 内存:4156kb
  • [2024-10-13 18:13:20]
  • 提交

answer

#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
//#define int long long
#define i128 __int128
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define ld double
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define chkmax(a,b) a=max(a,b)
#define chkmin(a,b) a=min(a,b)
#define rep(k,l,r) for(int k=l;k<=r;++k)
#define per(k,r,l) for(int k=r;k>=l;--k)
#define cl(f,x) memset(f,x,sizeof(f))
#define pcnt(x) __builtin_popcount(x)
#define lg(x) (31-__builtin_clz(x))
using namespace std;
void file_IO() {
//	system("fc .out .ans");
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
bool M1;
const int N=1e4+5;
ll f[2][N],g[2][N],w[N],h[N],d[N],ans[N];
vector<PII> vec[N];
struct dsu {
	int fa[N];
	void init(int n) {
		rep(i,0,n)
		fa[i]=i;
	}
	int find(int x) {
		if(fa[x]!=x)
			fa[x]=find(fa[x]);
		return fa[x];
	}
	void to(int u,int v) {
		fa[u]=v;
	}
}; dsu pre,suf;
void merge(int x,int n) {
	if(h[x]>=0) {
		int p=pre.find(x-1);
		pre.to(x,x-1);
		suf.to(x-1,x);
		d[p]+=d[x];
		int r=suf.find(x);
		if(r!=n) {
			++r;
			h[r]+=h[x];
			merge(r,n);
		}
	}
}
void solve() {
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,n)
	vec[i].clear();
	while(m--) {
		int l,r,val;
		scanf("%d%d%d",&l,&r,&val);
		vec[r].push_back(make_pair(l,val));
	}
	rep(i,0,n)
	f[0][i]=g[0][i]=-INFLL;
	f[0][0]=g[0][0]=0;
	rep(k,0,n) {
		rep(i,0,n) {
			w[i]=h[i]=-INFLL;
			d[i]=0;
			if(k)
				f[k&1][i]=g[k&1][i]=-INFLL;
		}
		pre.init(n);
		suf.init(n);
		rep(i,k,n) {
			if(k)
				g[k&1][i]=max(g[(k-1)&1][i-1],f[(k-1)&1][i-1]);
			w[i]=g[k&1][i];
			if(i!=k) {
				int x=pre.find(i-1);
				h[i]=(w[x]+d[x])-w[i];
				merge(i,i);
			}
			for(auto x:vec[i]) {
				int p=x.first,val=x.second;
				int l=pre.find(p),r=suf.find(p);
				d[l]+=val;
				if(r!=i) {
					++r;
					h[r]+=val;
					merge(r,i);
				}
			}
			if(i!=k) {
				int x=pre.find(i-1);
				f[k&1][i]=w[x]+d[x];
			}
		}
		ans[n-k]=max(f[k&1][n],g[k&1][n]);
	}
	rep(i,1,n)
	printf("%lld ",ans[i]);
	puts("");
}
bool M2;
signed main() {
	//file_IO();
	int testcase=1;
	scanf("%d",&testcase);
	while(testcase--)
		solve();
	fprintf(stderr,"used time = %ldms\n",1000*clock()/CLOCKS_PER_SEC);
	fprintf(stderr,"used memory = %lldMB\n",(&M2-&M1)/1024/1024);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4000kb

input:

2
4 3
0 2 3
3 4 2
0 3 1
3 1
1 3 100

output:

2 3 5 6 
0 100 100 

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 4064kb

input:

1000
2 9
0 2 396628655
1 2 268792718
0 2 16843338
1 2 717268783
0 1 693319712
0 1 856168102
1 2 407246545
1 2 527268921
0 1 536134606
6 2
2 5 451394766
0 5 695984050
9 7
0 6 73936815
2 9 505041862
4 5 223718927
5 7 179262261
3 5 449258178
0 5 493128
0 3 994723920
6 6
3 5 433389755
2 4 773727734
4 5 ...

output:

2085622420 4419671380 
0 0 451394766 451394766 1147378816 1147378816 
223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 
127680943 773727734 1334798432 2227456393 2675644351 2675644351 
976357580 1594205360 2103791342 2721639122 3241574409 3936588085 418...

result:

ok 1000 lines

Test #3:

score: 0
Accepted
time: 23ms
memory: 3900kb

input:

100
99 83
33 47 476927808
66 71 627937890
14 84 645468307
89 96 588586447
24 43 710156469
5 85 11308832
46 56 208427221
8 62 726478310
34 74 135993561
10 74 851555000
49 52 946936715
34 39 771067386
76 96 16233727
29 34 612324591
71 86 591062856
24 94 670656770
21 59 629389147
48 67 860046161
34 86 ...

output:

131347174 276869285 946936715 1078283889 1223806000 1355153174 1699007616 1969489139 1975876901 2246358424 2246358424 2721560040 2721560040 2998429325 3096939475 3110534651 3349497930 3724362755 4882915593 5014262767 5871777743 6003124917 6778566352 7530637253 7661984427 7661984427 7661984427 815857...

result:

ok 100 lines

Test #4:

score: 0
Accepted
time: 20ms
memory: 4024kb

input:

100
95 96
5 89 124321145
33 77 773363571
1 94 468188689
35 84 284660056
0 92 245485733
8 57 596788519
10 93 59267682
49 90 450355885
76 84 190264757
84 87 797853944
4 41 437909067
73 74 532217941
5 8 999048465
0 95 143672912
12 55 290639413
6 86 899138487
35 36 508500258
21 68 843227286
0 94 9058576...

output:

1272369836 1903674815 2748981113 2925702770 2951858051 3748029578 3924751235 3950906516 4545883522 4735350922 4912072579 5329793703 5734399387 5911121044 5946764048 6532253331 6708974988 6735130269 7316163512 7492885169 7519040450 7674437726 8074553640 8251275297 8277430578 8432827854 8609549511 871...

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 16ms
memory: 4088kb

input:

100
86 92
68 73 730593611
9 11 314305867
63 64 699021890
6 11 787982418
69 72 421876106
31 37 449645826
76 82 238642240
28 31 467098727
22 23 333165290
34 42 645351348
34 38 618797828
10 14 164751728
30 34 88922825
80 83 936426204
72 77 383499583
46 51 128937895
49 57 437892230
50 56 692509142
14 19...

output:

987528833 1943214328 2850671579 3750797988 4594973746 5293995636 5939438559 6537351768 7295198258 8185806974 9093264225 9993390634 10837566392 11598929402 12443105160 13088548083 13686461292 14053565377 14974356349 15874482758 16718658516 17480021526 18324197284 18999222924 19760585934 20604761692 2...

result:

ok 100 lines

Test #6:

score: 0
Accepted
time: 13ms
memory: 4016kb

input:

100
81 84
34 73 564718673
8 50 657489855
21 65 373282330
11 54 667584659
18 58 850348020
7 47 593942770
18 63 903492853
10 55 897217447
14 59 211655411
19 55 409828915
13 55 29599937
8 50 288981803
36 72 845363118
29 71 245960658
5 51 704846394
4 46 990499066
4 39 857206811
13 45 623803672
3 35 7771...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1579851645 1688016338 1688016338 2828615820 2936780513 2936780513 3154788497 3947417123 4844055621 5416102236 6085851635 7381675290 8016930442 8871843928 10210533499 11498381971 12614109011 13901957483 13901957483 14749882994 16086529293 ...

result:

ok 100 lines

Test #7:

score: 0
Accepted
time: 12ms
memory: 3980kb

input:

100
90 84
8 90 544067926
15 90 295641139
1 85 902318577
9 90 987378388
7 88 133595743
0 90 33207011
0 90 418600362
9 85 767527655
2 89 235369723
1 90 439147697
1 83 145434750
2 88 708179173
8 86 751546514
0 81 405752009
2 88 26193206
5 77 587219021
0 86 541362608
7 84 965163611
7 89 890265728
4 83 6...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 587219021 1031406396 1523585030 1523585030 1523585030 2678374149 3141571642 4854384801 6126474244 8978806560 11608076036 14734165356 16508213836 20090070737 2...

result:

ok 100 lines

Test #8:

score: 0
Accepted
time: 226ms
memory: 4156kb

input:

10
851 868
679 693 378192988
267 399 343857831
131 748 576579017
575 787 12204822
499 576 826908873
155 724 737312468
623 795 638740575
172 407 637837864
11 283 259084035
186 273 908657968
85 417 701461051
184 807 832409248
152 281 213019511
109 435 715286463
524 814 347540017
60 664 594004384
504 7...

output:

891385001 1219204255 1219204255 1516678750 1887587817 2215407071 2215407071 2512881566 2740735819 2753391924 3038210314 3050866419 3313797806 3541652059 3612342669 3839126554 3909817164 4280726231 4608545485 4608545485 4906019980 5133874233 5146530338 5465480444 5465480444 5762954939 5990809192 6003...

result:

ok 10 lines

Test #9:

score: 0
Accepted
time: 191ms
memory: 4008kb

input:

10
913 863
98 634 432130709
48 800 479851779
69 906 186774359
416 789 756411639
274 327 906033133
459 906 362923880
790 809 670510137
91 866 875171159
21 903 956639323
107 165 590430725
55 510 156036789
98 828 45500146
439 482 655902695
138 617 28938721
833 856 624732370
77 892 535654097
3 868 23177...

output:

418488187 966063397 1384551584 1826025664 2244513851 2542625088 2801740920 3099852157 3375801952 3634917784 3933029021 4197648871 4456764703 4754875940 4754875940 4822625709 5120736946 5227862880 5525974117 5525974117 5713687947 5891835123 6106424028 6156877401 6186674887 6484786124 6579410968 68775...

result:

ok 10 lines

Test #10:

score: 0
Accepted
time: 185ms
memory: 4152kb

input:

10
874 958
483 551 631858791
601 659 30225807
759 777 630132600
772 835 916633496
246 314 538628510
208 251 615840950
700 785 523731402
413 436 643299496
201 228 161288468
401 472 997421612
704 762 228097972
447 466 375836694
350 365 580675905
294 306 39388076
221 290 285200936
440 454 347252805
548...

output:

957614597 1612685590 2250760006 2881495320 3420983646 3734724339 4242003786 4555744479 5035470860 5349211553 5772752393 6086493086 6482898460 6796639153 7170903160 7484643853 7881049227 8194789920 8563367427 8877108120 9211409411 9525150104 9808380749 9998025568 10311766261 10594996906 10721590662 1...

result:

ok 10 lines

Test #11:

score: 0
Accepted
time: 151ms
memory: 4060kb

input:

10
961 924
90 532 71550121
310 699 446173607
415 936 223219513
6 531 905549873
322 876 879397647
339 789 150918417
199 612 126195703
180 667 404334728
258 714 879226371
314 875 62611196
162 658 204244054
142 689 614679390
363 887 544546349
302 846 546951131
433 951 529946158
347 882 343766215
11 542...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 10 lines

Test #12:

score: 0
Accepted
time: 108ms
memory: 4124kb

input:

10
898 919
8 797 50899375
29 891 494390299
7 893 602512657
56 882 930376306
53 827 162645369
45 886 590182657
61 824 346335916
116 895 129420744
0 898 462749196
4 887 532121466
12 743 760270355
22 854 738909464
3 876 300986641
1 843 561518289
105 852 851292970
27 889 940486169
20 884 120755595
88 89...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 10 lines

Test #13:

score: -100
Time Limit Exceeded

input:

1
10000 10000
4243 4355 678092074
417 1119 480129711
1423 4497 648552857
3970 7187 341033928
3562 9406 262707175
2221 7546 593247929
8687 9420 19219689
1203 8523 264021888
1234 2415 374691722
2826 7687 139199900
7658 8431 780718641
7761 8218 852678681
3240 7544 193841776
1110 9353 662982105
5712 938...

output:

588915533 672758678 1261674211 1261674211 1544748874 1867906031 1867906031 2150980694 2296343133 2369281050 2579417796 2652355713 2860989061 2866405141 3144063724 3289426163 3362364080 3572500826 3645438743 3790801182 3859488171 4073875845 4142562834 4283508095 4360863190 4566582758 4643937853 47213...

result: