QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379911 | #8572. Passing Game | ucup-team266# | AC ✓ | 63ms | 28084kb | C++14 | 2.6kb | 2024-04-06 19:51:17 | 2024-04-06 19:51:18 |
Judging History
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,246);
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]
if(s1&&s2){
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: 18088kb
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: 56ms
memory: 27368kb
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: 46ms
memory: 22152kb
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: 55ms
memory: 26448kb
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: 20164kb
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: 56ms
memory: 28084kb
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: 0
Accepted
time: 56ms
memory: 20192kb
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 70517421587512986 11224815513692355 71475323642044669 1805862419831112 135052117577413332 26429620406592108 30539122715657614 7984965510320702 45549957862209120 42689412604990122 11269234889588471 80025912449049377 62081070915081025 4881768842034...
result:
ok 6000 numbers
Test #8:
score: 0
Accepted
time: 55ms
memory: 21764kb
input:
3 100000 29147 500000000 597145750 552984982 372885743 640231243 733918327 800174654 803027973 174812114 914218248 958491647 953654602 654712814 719285245 331288273 879947652 879757804 768921697 826703535 228697076 180453233 681236422 977876007 50434656 229471634 830980737 12014073 250160020 4486414...
output:
13061698660 13061698660 13061698660
result:
ok 3 number(s): "13061698660 13061698660 13061698660"
Test #9:
score: 0
Accepted
time: 56ms
memory: 20244kb
input:
30000 10 10 802030518 640274071 71550121 799843967 796619138 223219513 312183499 673542337 879397647 631413076 598196518 983359971 96204862 446173607 402690754 668171337 905549873 566661387 434495917 150918417 10 10 224422012 525305826 404334728 998133227 59632864 62611196 296576565 812713672 614679...
output:
69273774453668369 15440670445128286 192723941525693508 75675642974614068 36131012282542320 85171320762046356 27782956555892610 12331410768391077 241652836554719225 121097012285620735 382589380847694270 12204787868953675 98646491955517787 1209132821823955 27110849050473250 137126106329510200 13480620...
result:
ok 30000 numbers
Test #10:
score: 0
Accepted
time: 55ms
memory: 20152kb
input:
1000 300 17 500000000 547680479 781514046 768736762 934177391 660698970 809576345 537077801 400529937 552145378 49225712 834259550 51888621 391560261 738261701 593590260 941618125 274782375 90195859 126157143 355402134 726699436 444190441 440061055 788686954 990218202 257424993 544553505 853414019 9...
output:
13061698660 13061698660 14069829018 14596599454 13061698660 13061698660 14901483521 13061698660 13061698660 13061698660 13061698660 14069829018 13061698660 13061698660 13061698660 13061698660 15506866876 13061698660 13061698660 13814295534 14596599454 13303815695 14901483521 13061698660 13061698660 ...
result:
ok 1000 numbers
Test #11:
score: 0
Accepted
time: 48ms
memory: 20520kb
input:
300 1000 542 657869894 302751325 821704902 911667041 556158495 811890152 474105790 363136546 201743030 341427747 10486332 162407523 544009771 915779647 988646785 755731062 331696864 259116972 66705678 553069290 70812533 281275932 273721508 355438226 887037644 725648767 659562563 410301053 783671813 ...
output:
1092574991858418 761786727410942 3837016071362107 4542837085930755 1215985900981157 2188923692733333 4724138820804551 3324015510566471 2123768018381713 2664228765301178 4591721575190483 4991118275259893 7874488069466712 4072341567396137 998993874951943 1397368267257796 2024987292950682 1402861394900...
result:
ok 300 numbers
Test #12:
score: 0
Accepted
time: 57ms
memory: 20184kb
input:
1200 250 98 682351638 2457996 288493156 128440451 375428233 891376236 17918276 143663203 560377768 514150164 700942749 574491970 506401375 254841922 745178877 456835709 62543579 179900914 263948337 646651057 32290953 664841057 559233349 634390971 335337494 369694988 197557638 400610487 227953519 629...
output:
23329812933206870 11277348901796038 12460508031437621 4895620700942690 738669449014040 6869250331331536 14681765643935973 5909108244560941 8421544152021567 13989985278118862 3639891463249160 8674001937254098 8255466194121077 1446947895929841 26707292420650755 17639851523757433 6242204086605175 11329...
result:
ok 1200 numbers
Test #13:
score: 0
Accepted
time: 55ms
memory: 20208kb
input:
300 1000 963 500000000 632915000 478910239 468205019 9987953 883339014 647780152 655126145 886106275 184298894 457965768 661511802 205781642 799243104 880841413 517330574 936864266 27921304 287252316 172487672 258054117 961443776 549407378 348055591 499999965 199391494 642934159 204368698 896164152 ...
output:
13061698660 14069829018 13061698660 14901483521 13061698660 13061698660 13303815695 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 14596599454 13303815695 13061698660 13061698660 14327495899 13061698660 13061698660 13061698660 14596599454 ...
result:
ok 300 numbers
Test #14:
score: 0
Accepted
time: 57ms
memory: 20864kb
input:
12 25000 4157 299336960 546808795 459692983 341866176 220959265 984680630 584146182 306737776 774447523 349601875 352671784 513138426 836883003 440483252 976958324 593873668 864213983 324458784 796561533 966591603 729088963 586303004 970759705 749529197 686341724 836687212 849079388 102598485 973778...
output:
284195910875626 274870514836051 404258435833079 135833080069129 176065859803454 133679933287499 369257036588126 220782753354879 212328718914556 450834372738126 197127000261514 105626494759545
result:
ok 12 numbers
Test #15:
score: 0
Accepted
time: 51ms
memory: 20348kb
input:
60 5000 1699 756662829 164615679 176745065 930641599 992714840 890646201 828015603 245741385 937343509 804090603 265947390 767999938 20283091 135162900 724431387 59623628 922934339 613174775 91621915 821163847 576884311 744574611 129855504 546339925 888037696 291592234 88692553 740078934 604296047 9...
output:
1388747109016135 796585908548315 1292842362023432 1019969421104496 699679635678647 284970927437972 1976026267696309 1262333683751669 476479031653348 836032814722947 401067691094076 224470179417906 812877199901981 1577911241094002 409665098471103 1335490113314524 688097777617304 597433042398934 10793...
result:
ok 60 numbers
Test #16:
score: 0
Accepted
time: 57ms
memory: 25072kb
input:
1 300000 79048 500000000 72303450 725956278 499829564 769524290 887183343 104695544 500558244 976713897 178100565 346465068 438866193 47040800 998435764 833218621 833033990 284438519 526206362 989981879 970886760 73797241 676341166 573983229 922343350 509988168 439937579 19085346 575750193 311019854...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #17:
score: 0
Accepted
time: 58ms
memory: 26624kb
input:
1 300000 2 500000000 986689313 526988696 742766790 886595836 687905439 41623509 489823328 956671241 445393626 311276990 738982299 809517071 426531977 503452845 773412198 578933597 469709362 697592748 973076959 311235585 161052090 760002550 831554209 688007794 457851620 198717375 753343317 49564457 7...
output:
14901483521
result:
ok 1 number(s): "14901483521"
Test #18:
score: 0
Accepted
time: 54ms
memory: 25336kb
input:
1 300000 17895 500000000 961738248 799804319 862125039 29383909 88522421 206249306 205254278 326598156 712641955 461957852 280478849 699192392 10039427 253283343 742404721 629158607 876458637 210361887 315760729 524741657 237413472 924215264 607715874 385443844 457796693 882601269 454562263 28028030...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #19:
score: 0
Accepted
time: 63ms
memory: 26492kb
input:
1 300000 10 500000000 616829345 738394523 653934048 46980218 822233301 704878277 425893750 793326584 314412433 119413358 893207432 392314189 886191961 773036754 716141312 651831880 378682454 142441780 861010208 140408545 821733429 756055372 762602717 66579867 260154480 709785435 723760183 667143439 ...
output:
13814295534
result:
ok 1 number(s): "13814295534"
Test #20:
score: 0
Accepted
time: 58ms
memory: 27524kb
input:
1 300000 162598 500000000 178424286 321857556 392783865 938614528 700858738 880246121 30385725 540666710 934016590 540732817 312471486 672034801 725649082 609741540 237602792 838632938 467171051 355767291 94570869 36304257 751174881 377429057 222564767 455767609 799398247 607276965 841670683 8203258...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #21:
score: 0
Accepted
time: 51ms
memory: 27488kb
input:
1 300000 3 500000000 10640626 26244594 885618738 664684363 927460604 21605214 141448118 254610947 722072932 749730723 381408442 617124215 660295243 265990282 949209956 870823956 890190598 345267809 604438056 233614156 179167636 646003555 57529751 371559531 669193525 518674390 823682615 687712382 808...
output:
14596599454
result:
ok 1 number(s): "14596599454"
Test #22:
score: 0
Accepted
time: 51ms
memory: 20332kb
input:
60 5000 784 500000000 181933656 247700033 127137924 488746354 696015683 240485749 283778545 824036313 914909253 606068043 424412515 445204997 474299591 99548917 252196353 792967047 957143976 973486259 68189163 296428949 521704790 687088714 585678966 710330302 393693418 67215218 238595352 58967541 40...
output:
13061698660 13559037370 14901483521 13061698660 13814295534 15506866876 13559037370 13559037370 13559037370 13061698660 13061698660 13061698660 13061698660 13061698660 14596599454 13061698660 14596599454 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 14327495899 13061698660 ...
result:
ok 60 numbers
Test #23:
score: 0
Accepted
time: 59ms
memory: 26488kb
input:
1 300000 112925 500000000 187720638 774041899 719124389 144433388 722401729 514163966 358695852 613043018 211475688 785946211 346266738 885638445 520855439 83336659 482573610 909962503 70509919 170194067 87226103 644860310 982300924 929716289 601580680 989819441 432098173 936284417 882766775 8075610...
output:
12940360625
result:
ok 1 number(s): "12940360625"
Test #24:
score: 0
Accepted
time: 45ms
memory: 20272kb
input:
12 25000 20692 500000000 132857017 385523215 701066726 666661361 179540297 242239729 2197758 416327322 907621491 282200769 397832072 157059359 196291390 257407253 333935727 710782843 308141598 611903784 773877005 500001291 235246551 566392891 131837214 229389993 687718767 452527218 435117876 7896945...
output:
13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 13061698660 13559037370 13559037370 14596599454 13061698660
result:
ok 12 numbers
Test #25:
score: 0
Accepted
time: 55ms
memory: 26252kb
input:
1 300000 8 500000000 326439190 791622036 104665080 329000514 468690410 637698668 136597156 109652773 316454352 546873850 474979574 901965339 380355588 124495260 592541006 835608163 892994257 184061276 74037627 398052013 304885056 370370537 529146672 419570552 996293468 482282900 931347113 436336231 ...
output:
14069829018
result:
ok 1 number(s): "14069829018"
Test #26:
score: 0
Accepted
time: 47ms
memory: 25860kb
input:
1 300000 0 500000000 238939486 304374455 423669374 29850387 438300513 111174976 329099666 874056474 588817943 421125375 506161650 223516602 213027370 93945112 455298822 417963043 769012969 799258806 709005309 79578465 815399909 939019510 616037013 308568881 537790300 119192633 871465935 352029430 40...
output:
15506866876
result:
ok 1 number(s): "15506866876"
Test #27:
score: 0
Accepted
time: 48ms
memory: 25996kb
input:
1 300000 8 500000000 961512480 541527048 81341659 448136384 344171271 159634569 75744344 944062332 74181957 328827482 239656051 229157158 759548731 123296963 504290696 338403912 35032736 85336690 365820634 950731848 862862483 408781872 200982012 334906331 824315049 261157081 412945433 364182738 9395...
output:
14069829018
result:
ok 1 number(s): "14069829018"
Test #28:
score: 0
Accepted
time: 43ms
memory: 25776kb
input:
1 300000 127477 500000000 924603745 709414871 289466706 323340589 241488399 890485618 975344668 720001574 536087490 437923628 22861967 266855378 971340750 162468536 150815332 951025602 690120654 555801138 803553804 49036941 959174045 303264032 297460064 413061866 964223878 105359201 116733261 478018...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #29:
score: 0
Accepted
time: 60ms
memory: 26980kb
input:
1 300000 7711 500000000 748435576 478482708 132592520 144810784 179561097 534551204 216378223 550689198 602762045 672262297 963816921 641701358 643658260 837556308 197842642 513366325 778171216 318005265 66736234 581114229 674030621 956781094 438434388 985504937 875113774 24034696 920968426 27468111...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #30:
score: 0
Accepted
time: 55ms
memory: 25516kb
input:
1 300000 196959 500000000 803909108 287035995 504828814 502231638 398508717 129657414 275047043 10674111 998776022 470168059 574012819 135318042 637203040 592738673 376455038 104938668 524920759 198815750 183979799 493025480 108537792 527769385 907720916 134661241 27000849 49127777 547472548 9312769...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #31:
score: 0
Accepted
time: 59ms
memory: 25712kb
input:
1 300000 60984 500000000 422362911 114135400 592480923 746334952 456767366 271308069 223807842 893538164 178332416 669320868 448048330 360818676 245670700 413899870 612763740 619621624 41470340 263166441 43785120 748504916 298549369 848364437 207051521 889775639 938698993 347177517 576889437 7384056...
output:
13061698660
result:
ok 1 number(s): "13061698660"
Test #32:
score: 0
Accepted
time: 62ms
memory: 25748kb
input:
1 300000 4 500000000 660166004 713903083 813679046 625552963 93302943 675044519 897009216 806482499 523988918 77645889 407549130 211912486 653340703 796334042 366635826 519181228 865605695 363006757 714920677 892233195 308118610 214573620 94767292 739715338 600232897 783047358 341011849 777450639 76...
output:
14596599454
result:
ok 1 number(s): "14596599454"
Test #33:
score: 0
Accepted
time: 56ms
memory: 27704kb
input:
1 300000 13 500000000 83707701 186780969 326025057 502607635 598749883 766935984 146637842 473143286 696680611 341825420 927633891 263175759 689933039 259521054 793063933 894532511 574312702 536759906 217418205 172344593 323427755 392477347 297320666 37532029 352872806 463150694 190001405 887909498 ...
output:
13303815695
result:
ok 1 number(s): "13303815695"
Extra Test:
score: 0
Extra Test Passed