QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379883#8572. Passing Gameucup-team266#WA 63ms28272kbC++142.6kb2024-04-06 19:41:432024-04-06 19:41:43

Judging History

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

  • [2024-04-06 19:41:43]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:28272kb
  • [2024-04-06 19:41:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
ll X[301000],G[300100];
#define pi pair<ll,ll>
#define mp make_pair
const int I=1e9;
const ll I2=1e18;
#define pb push_back
#define F first
#define S second
ll d1[301000],d2[300100],o1[300100],o2[301000];
ll d1_[301000],d2_[301000];
int s1,s2;
pi sta[301000];int top;
pi operator - (const pi &a,const pi &b){return mp(a.F-b.F,a.S-b.S);}
__int128 cro(pi a,pi b){return ((__int128)a.F)*b.S-((__int128)b.F)*a.S;}
ll E(pi a,ll x){return a.F*x+a.S;} 
void sol(){
	scanf("%d%d",&n,&m);m=min(m,128);
	vector<pi>v1,v2;
	for(int i=1;i<=n;i++)scanf("%lld",&X[i]);
	for(int i=1;i<=n;i++)scanf("%lld",&G[i]);
	if(n==1){puts("0");return;}
	if(X[1]>X[n]){for(int i=1;i<=n;i++)X[i]=I+1-X[i];}
	for(int i=2;i<n;i++){
		if(X[i]>X[n])continue;
		if(X[i]<X[1])v1.pb(mp(X[1]-X[i],G[i]));
		else v2.pb(mp(X[i]-X[1],G[i]));
	}
	sort(v1.begin(),v1.end()),sort(v2.begin(),v2.end());
	vector<pi>fz;
	ll ns=G[1];
	for(pi e:v1)if(ns>e.S)ns=e.S,fz.pb(e);v1=fz;
	fz.clear();
	ns=G[1];
	for(pi e:v2)if(ns>e.S)ns=e.S,fz.pb(e);v2=fz;
	ll ans=(X[n]-X[1])*G[1];
	s1=v1.size(),s2=v2.size();
	d1[0]=d2[0]=0;
	for(int i=1;i<=s1;i++)o1[i]=((i>1)?v1[i-2].S:G[1])*(v1[i-1].F-((i>1)?v1[i-2].F:0)),d1[i]=d1[i-1]+o1[i];
	for(int i=1;i<=s2;i++)o2[i]=((i>1)?v2[i-2].S:G[1])*(v2[i-1].F-((i>1)?v2[i-2].F:0)),d2[i]=d2[i-1]+o2[i];
	if(s2)ans=min(ans,d2[s2]+v2[s2-1].S*(X[n]-X[1]-v2[s2-1].F));
	for(int e=1;e<=m;e++){
		for(int i=1;i<=s1;i++)ans=min(ans,d1[i]+(X[n]-X[1]+v1[i-1].F)*v1[i-1].S);
		for(int i=1;i<=s1;i++)d1_[i]=I2;for(int i=1;i<=s2;i++)d2_[i]=I2;
		//d1_i+S[i](X[i]+X[j])->d2[j]
		top=0;
		for(int i=s1;i;i--){
			pi ut=mp(v1[i-1].S,d1[i]+v1[i-1].S*v1[i-1].F);
			while(top>1&&cro(sta[top]-sta[top-1],ut-sta[top])<=0)top--;
			sta[++top]=ut;
		}
		for(int i=s2,j=1;i;i--){
			ll A=v2[i-1].F;
			while(j<top&&E(sta[j],A)>E(sta[j+1],A))j++;
			d2_[i]=min(d2_[i],E(sta[j],A));
		}
		top=0;
		for(int i=s2;i;i--){
			pi ut=mp(v2[i-1].S,d2[i]+v2[i-1].S*v2[i-1].F);
			while(top>1&&cro(sta[top]-sta[top-1],ut-sta[top])<=0)top--;
			sta[++top]=ut;
		}
		for(int i=s1,j=1;i;i--){
			ll A=v1[i-1].F;
			while(j<top&&E(sta[j],A)>E(sta[j+1],A))j++;
			d1_[i]=min(d1_[i],E(sta[j],A));
		}
		for(int i=2;i<=s1;i++)d1_[i]=min(d1_[i],d1_[i-1]+o1[i]);
		for(int i=2;i<=s2;i++)d2_[i]=min(d2_[i],d2_[i-1]+o2[i]);
		for(int i=1;i<=s1;i++)d1[i]=d1_[i];
		for(int i=1;i<=s2;i++)d2[i]=d2_[i];
		for(int i=1;i<=s2;i++)ans=min(ans,d2[i]+(X[n]-X[1]-v2[i-1].F)*v2[i-1].S);
	}
	printf("%lld\n",ans);
}
int main(){
	int T;scanf("%d",&T);
	while(T--)sol();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4 2
3 2 1 6
3 1 1 3
2 0
1 2
1 2

output:

7
1

result:

ok 2 number(s): "7 1"

Test #2:

score: 0
Accepted
time: 63ms
memory: 26640kb

input:

1
300000 204334
809492393 304618667 173130445 377106790 364888630 949045125 622060683 557772818 216607577 848817467 862855568 507840723 120816645 639713488 741781998 682531787 685261161 601686403 355792373 162819930 710057718 234560726 998604853 678957602 485413982 855985802 109303681 979706626 4822...

output:

31313390701066

result:

ok 1 number(s): "31313390701066"

Test #3:

score: 0
Accepted
time: 50ms
memory: 21712kb

input:

3
100000 65460
217141764 710454586 789075415 24849107 685675008 839804815 638763480 327755609 43827967 390187172 301370841 622696676 598237196 232099091 211987715 416876077 572665966 73382836 520033984 808399404 752832432 341795744 434460344 535426588 136624537 997406768 297342165 558882675 26863877...

output:

70635841128944
47230361360721
59110547802683

result:

ok 3 number(s): "70635841128944 47230361360721 59110547802683"

Test #4:

score: 0
Accepted
time: 54ms
memory: 26336kb

input:

1
300000 101975
207258305 525434317 528778163 645316642 562113679 143398489 9114413 669854123 106324041 841914487 21419012 308025536 689200225 263298218 39377353 860366080 24610184 43404209 529054797 902238799 422737070 484129934 967667618 953541323 338625285 115085955 363490839 998893783 877857789 ...

output:

40311829457542

result:

ok 1 number(s): "40311829457542"

Test #5:

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

input:

18
17 0
500000000 499999997 500000010 499999965 500000118 499999609 500001291 499995739 500014064 499953589 500153157 499494579 501667889 494495965 518163316 440061055 697798520
197798520 59938945 18163316 5504035 1667889 505421 153157 46411 14064 4261 1291 391 118 35 10 3 1
17 1
500000000 499999997...

output:

15506866876
14901483521
14901483521
14596599454
14596599454
14327495899
14327495899
14069829018
14069829018
13814295534
13814295534
13559037370
13559037370
13303815695
13303815695
13061698660
13061698660
13061698660

result:

ok 18 numbers

Test #6:

score: 0
Accepted
time: 57ms
memory: 28272kb

input:

1
300000 108311
562733523 631963246 813519221 169288073 117366252 527887631 958029417 190367625 583075950 97173270 896048212 131308006 37400006 90012864 923307076 279518077 383193505 134227338 223315078 230865002 126513901 226753074 767298214 632275980 328061909 158106292 275417458 205909246 6796599...

output:

22530954433990

result:

ok 1 number(s): "22530954433990"

Test #7:

score: -100
Wrong Answer
time: 59ms
memory: 20196kb

input:

6000
50 9
134170081 235040736 405102476 567954026 351391400 872095141 116079799 935104039 779623552 857355273 642352783 394389351 10847154 403727586 104520573 266338849 213345479 719882827 836874283 973992590 698097800 821674140 408510849 363267881 10753022 371526254 123631785 246871721 505280626 29...

output:

30096348366675791
46069208396039888
43208901362730729
61230301838981076
11224815513692355
71475323642044669
1805862419831112
135052117577413332
26429620406592108
30539122715657614
7984965510320702
45549957862209120
42689412604990122
11269234889588471
80025912449049377
62081070915081025
4881768842034...

result:

wrong answer 4th numbers differ - expected: '70517421587512986', found: '61230301838981076'