QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#451404#8304. Key Project-OfastTL 927ms40824kbC++982.7kb2024-06-23 10:53:142024-06-23 10:53:14

Judging History

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

  • [2024-06-23 10:53:14]
  • 评测
  • 测评结果:TL
  • 用时:927ms
  • 内存:40824kb
  • [2024-06-23 10:53:14]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e4+10;
vector <int> P[N],Q[N];
int n,m,dis[N],a[N],b[N],c[N],d[N];
namespace MCMF{
	const int N=1e6+10;
	int n,s,t,head[N],to[N],nxt[N],f[N],tmphead[N],c[N],cnt=-1;
	int maxflow,mincost;
	void add(int u,int v,int fl,int w){
		++cnt;
		nxt[cnt]=head[u];
		head[u]=cnt;to[cnt]=v;
		f[cnt]=fl;c[cnt]=w;
		++cnt;
		nxt[cnt]=head[v];
		head[v]=cnt;to[cnt]=u;
		f[cnt]=0;c[cnt]=-w;
	}
	int dis[N],vis[N],pre[N][2];
	struct Queue{
		int head,tail,a[N];
		void push(int x){a[++tail]=x;}
		void pop(){++head;}
		int size(){return tail-head+1;}
		int front(){return a[head];}
	}q;
	void SPFA(){
		q.head=q.tail=0;
		for(int i=0;i<=n;i++)dis[i]=1e9,vis[i]=0;
		q.push(s);vis[s]=1;dis[s]=0;
		int cur=0;
		while(q.size()){
			int u;
			if(cur==0){
				u=q.a[q.head++];
			}else u=q.a[q.tail--];
			vis[u]=0;
			for(int i=head[u];~i;i=nxt[i]){
				int v=to[i],w=c[i];
				if(!f[i])continue;
				if(dis[v]>dis[u]+w){
					dis[v]=dis[u]+w;
					pre[v][0]=u;
					pre[v][1]=i;
					if(!vis[v]){
						q.push(v);vis[v]=1;
					}
				}
			}
		}	
	}
	int pid[N],qid[N];
	void solve(){
		while(true){
			int tmp=cnt;
			for(int i=0;i<=n;i++)tmphead[i]=head[i];
			for(int i=1;i<=::n;i++){
				if(P[i].size())add(s,i,1,P[i].back()),pid[i]=cnt;
				if(Q[i].size())add(i,t,1,Q[i].back()),qid[i]=cnt;
			}
			SPFA();
			if(dis[t]==1e9)return;
			int minf=1e9,sumc=0,now=t;
			vector <int> path;
			while(now!=s){
				path.push_back(pre[now][1]);
				minf=min(minf,f[pre[now][1]]);
				sumc+=c[pre[now][1]];
				now=pre[now][0];
			}
			for(int i=0;i<path.size();i++){
				f[path[i]]-=minf;
				f[path[i]^1]+=minf;
			}
			for(int i=1;i<=::n;i++){
				if(P[i].size()&&f[pid[i]])P[i].pop_back();
				if(Q[i].size()&&f[qid[i]])Q[i].pop_back();
			}
			cnt=tmp;
			for(int i=0;i<=n;i++)head[i]=tmphead[i];
			mincost+=minf*sumc;
			cout<<mincost<<"\n";
		}
	}
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	memset(MCMF::head,-1,sizeof(MCMF::head));
	cin>>n>>m;
	for(int i=1;i<n;i++)
		cin>>dis[i];
	for(int i=1;i<=m;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<=m;i++)
		cin>>c[i]>>d[i];
	MCMF::t=n+1;
	MCMF::s=0;
	MCMF::n=MCMF::t;
	for(int i=1;i<n;i++){
		MCMF::add(i,i+1,1e9,dis[i]);
		MCMF::add(i+1,i,1e9,dis[i]);
	}
	for(int i=1;i<=m;i++){
		Q[a[i]].push_back(b[i]);
	}
	for(int i=1;i<=m;i++){
		P[c[i]].push_back(d[i]);
	}
	for(int i=1;i<=n;i++){
		sort(Q[i].begin(),Q[i].end());
		sort(P[i].begin(),P[i].end());
		reverse(Q[i].begin(),Q[i].end());
		reverse(P[i].begin(),P[i].end());
	}
	MCMF::solve();
	cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
	return 0;
}

詳細信息

Test #1:

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

input:

4 3
1 1 1
1 1
1 2
4 6
2 1
2 2
3 5

output:

3
8
20

result:

ok 3 lines

Test #2:

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

input:

50 500
118837 951904 671499 484461 639888 359339 502649 627559 5961 20812 433609 905677 200996 201161 615383 263424 151528 844324 472585 154315 741222 247963 722818 858419 386517 100125 931060 752896 865319 23063 949988 220229 897126 259228 583375 813279 112033 676073 925357 53124 394997 392593 4992...

output:

249916
1627724
4297306
7521922
11058813
14819098
18595354
22833314
27397118
32192806
38169968
44605698
51210995
57983422
65947214
73960441
82121445
90336822
99546401
109165243
119438147
129792015
140327562
150872437
161950777
173380273
185460073
198299711
211179357
224215634
237469142
251993186
2668...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 17ms
memory: 37912kb

input:

100 5000
161024 333083 427714 106026 344162 443967 300826 786012 190136 836472 739686 718645 621258 379491 896890 853718 132289 761595 425423 238212 266456 878908 987607 383196 425157 464423 910874 113988 596436 427196 677260 53939 353039 610651 203820 412321 810742 75711 522237 749361 213154 313223...

output:

244596
673367
1114774
1653086
2235799
2859280
3550743
4328294
5111265
5970416
6833438
7698546
8596718
9537334
10673653
11841335
13117454
14432273
15830547
17278727
18734845
20229311
21782032
23362360
24997850
26692528
28391424
30147387
31907288
33748546
35691188
37645806
39609940
41609598
43629263
4...

result:

ok 5000 lines

Test #4:

score: 0
Accepted
time: 227ms
memory: 38364kb

input:

300 20000
589233 424913 26472 555010 877553 764101 539779 342418 861724 439040 459313 518843 421817 463969 416326 348384 802183 187604 666745 329607 31379 864405 383948 216216 214607 823562 806785 481248 308705 60717 10231 892503 634831 778333 229345 254773 810990 139390 203897 878093 12605 556113 7...

output:

100488
213140
349180
573842
815426
1116056
1462744
1812722
2244746
2703883
3174800
3651102
4147393
4650694
5158675
5668646
6183335
6716217
7283456
7888069
8500618
9122205
9750795
10400551
11050357
11710647
12415089
13120968
13843813
14567012
15300273
16039492
16782040
17525930
18274542
19025483
1979...

result:

ok 20000 lines

Test #5:

score: 0
Accepted
time: 926ms
memory: 39424kb

input:

500 50000
389931 323526 397980 127878 810602 175326 183833 681018 182880 117266 603325 622561 639554 107960 301053 423699 585725 728312 759747 401710 708795 716319 677907 222410 106480 693183 12062 99078 319397 27265 184818 547305 591605 673437 248572 838416 783112 514511 590199 304268 743695 152614...

output:

28948
81176
142183
274273
412436
564080
723576
907555
1106837
1312014
1542499
1776945
2029643
2293083
2564408
2845238
3127258
3429326
3734724
4077784
4422610
4769373
5120211
5471271
5829254
6193440
6559204
6925157
7299056
7676687
8055873
8443295
8835706
9228277
9633028
10040983
10449860
10867427
112...

result:

ok 50000 lines

Test #6:

score: 0
Accepted
time: 918ms
memory: 37876kb

input:

500 50000
814225 718009 509305 663885 692938 81949 338865 256208 633763 538065 610352 418799 569529 240073 343174 858775 891248 978222 901898 541225 323850 259144 910646 494961 849671 631595 295951 684765 524225 528563 429209 29451 321964 184405 921803 6456 513800 394234 893204 858219 803508 851048 ...

output:

32751
89317
166464
257082
348771
490700
648348
829128
1048079
1268375
1494342
1728593
1974587
2230719
2490912
2751796
3018462
3288633
3567772
3849039
4133945
4422081
4712826
5006032
5300689
5605787
5917468
6231159
6553893
6879972
7225427
7587043
7954449
8323543
8693476
9063928
9452161
9842002
102336...

result:

ok 50000 lines

Test #7:

score: 0
Accepted
time: 924ms
memory: 40824kb

input:

500 50000
297562 973909 125150 594402 338413 800413 807418 507160 762601 679162 117527 20844 475754 356840 543005 70892 856074 111791 693020 842664 379999 451111 352568 516972 38094 960557 817785 653832 326000 388241 480706 997676 661863 872152 825240 622564 472444 781153 531220 657266 724498 325778...

output:

28166
61873
140869
265278
443959
623089
818253
1016724
1217343
1421306
1632243
1847700
2063786
2291906
2521700
2764826
3013266
3266487
3531216
3798951
4069988
4349099
4628951
4917513
5214365
5526450
5842545
6160755
6488215
6825410
7166464
7516286
7889086
8264302
8645444
9036030
9428791
9827768
10232...

result:

ok 50000 lines

Test #8:

score: 0
Accepted
time: 927ms
memory: 38940kb

input:

500 50000
408111 405860 980043 244502 311678 482866 300809 331874 724233 686311 305918 921260 327868 264944 224337 60710 593865 827670 626005 558689 715008 629254 291239 622999 57298 716794 670939 203622 748638 54966 498570 206475 563919 824272 225928 601663 486714 340463 817279 395076 532063 800143...

output:

80084
176593
273344
375931
481391
606044
736304
909760
1086021
1262904
1452696
1652385
1857661
2063357
2273828
2486817
2704613
2927180
3153212
3385254
3625587
3873051
4123281
4384294
4686927
4998140
5310843
5638828
5967724
6302992
6652379
7023175
7404980
7787562
8182298
8577298
8991930
9407686
98253...

result:

ok 50000 lines

Test #9:

score: 0
Accepted
time: 916ms
memory: 38388kb

input:

500 50000
703208 823547 632637 178774 648651 458695 96199 358770 115928 927436 857218 361999 105219 439431 173221 420730 210746 277490 347827 223309 801169 990535 254826 891578 171302 588559 520074 848546 936074 152062 84313 777995 487205 35420 33252 911491 338044 15007 545355 157980 564896 752072 4...

output:

33529
91228
176794
266503
371225
485659
610172
737133
871818
1012054
1187727
1383936
1589771
1795652
2007656
2228517
2468727
2712610
2961785
3219731
3499027
3779450
4063079
4347539
4657775
4992805
5335755
5681509
6033314
6388252
6748720
7121845
7495911
7871061
8247465
8625010
9006086
9389592
9793528...

result:

ok 50000 lines

Test #10:

score: -100
Time Limit Exceeded

input:

500 50000
242856 565385 293999 248736 846080 978802 200015 927271 485007 108798 159645 350738 353068 312679 967787 507335 645006 837349 666737 670595 65293 892786 811248 115947 141849 170196 502710 517577 259465 501057 215175 524776 667409 469241 279758 997997 766812 880321 94837 296922 507701 86701...

output:

119658
350300
636153
948337
1274276
1601194
1936951
2293382
2651739
3018681
3390346
3764093
4140227
4539759
4952779
5382203
5814148
6251115
6707056
7184104
7663241
8144517
8635227
9148208
9662383
10177591
10693998
11227547
11785628
12345934
12913101
13507548
14103275
14704697
15309011
15917851
16533...

result: