QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574455#9222. Price ComboEXODUSAC ✓308ms77404kbC++171.8kb2024-09-18 22:10:462024-09-18 22:10:46

Judging History

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

  • [2024-09-18 22:10:46]
  • 评测
  • 测评结果:AC
  • 用时:308ms
  • 内存:77404kb
  • [2024-09-18 22:10:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N=4e5+7;
constexpr ll inf=0x3f3f3f3f3f3f3f3f;
void cmin(ll &x,ll y){x=min(x,y);}
int n,a[N],b[N],pos[N];
tuple<int,int,int>h[N];
ll f[N][4];
struct node{
	int trp[4];
	ll trv[4];
	friend node operator +(const node &lhs,const node &rhs){
		node res;
		for(int i=0;i<4;i++)
			res.trp[i]=rhs.trp[lhs.trp[i]],res.trv[i]=lhs.trv[i]+rhs.trv[lhs.trp[i]];
		return res;
	}
}t[N<<2],e{{0,1,2,3},{0,0,0,0}};
int ls(int k){return k<<1;}
int rs(int k){return k<<1|1;}
void pull(int k){t[k]=t[ls(k)]+t[rs(k)];}
void build(int k,int l,int r){
	if(l==r)return t[k]=e,void();
	int mid=(l+r)>>1;
	build(ls(k),l,mid),build(rs(k),mid+1,r);
	return pull(k);
}
void modify(int k,int l,int r,int p,node v){
	if(l==r)return t[k]=v,void();
	int mid=(l+r)>>1;
	if(p<=mid)modify(ls(k),l,mid,p,v);
	else modify(rs(k),mid+1,r,p,v);
	return pull(k);
}
node query(int k,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr)return t[k];
	int mid=(l+r)>>1;node res=e;
	if(ql<=mid)res=res+query(ls(k),l,mid,ql,qr);
	if(mid<qr)res=res+query(rs(k),mid+1,r,ql,qr);
	return res;
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],h[i]={a[i],i,0};
	for(int i=1;i<=n;i++)cin>>b[i],h[n+i]={b[i],i,1};
	sort(h+1,h+2*n+1);build(1,1,2*n);
	memset(f,0x3f,sizeof(f));
	memset(f[0],0,sizeof(f[0]));
	for(int i=1;i<=2*n;i++){
		auto [w,p,tp]=h[i];node cur;
		if(tp)cur=(node){{2,3,0,1},{0,0,w,w}};
		else cur=(node){{1,0,3,2},{0,w,0,w}};
		int k=pos[p];
		pos[p]=i;
		if(k){
			node res=query(1,1,2*n,k+1,i-1)+cur;
			for(int j=0;j<4;j++)cmin(f[i][j],f[i-1][j]),cmin(f[i][res.trp[j]],f[k-1][j]+res.trv[j]);
		}else{
			modify(1,1,2*n,i,cur);
			for(int j=0;j<4;j++)f[i][cur.trp[j]]=f[i-1][j]+cur.trv[j];
		}
	}
	cout<<f[2*n][0]<<'\n';
	return 0;
}

详细

Test #1:

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

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

131

result:

ok single line: '131'

Test #2:

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

input:

7
10 12 19 99 10 8 49
9 14 15 199 11 7 19

output:

131

result:

ok single line: '131'

Test #3:

score: 0
Accepted
time: 216ms
memory: 77260kb

input:

199913
1212731 2525164 3210261 2457211 1013738 1931420 923123 867112 762069 2108660 108920 2491869 867107 387025 2278045 574027 1661570 820133 1274150 2001346 779766 3305537 3000211 2418643 2108660 2001343 1074820 2754411 826712 3117447 1661569 338161 1849064 3007920 3057426 468078 3252798 1274146 4...

output:

154816494865

result:

ok single line: '154816494865'

Test #4:

score: 0
Accepted
time: 169ms
memory: 75144kb

input:

200000
97216869 743886950 33071099 93740214 165915739 714765240 770423425 498199793 631193672 753722174 569396548 842251035 911607641 450531347 765200530 739362614 91640365 174209387 248940417 335559443 238573490 479206903 882783448 200485674 717481029 526848873 692757023 616376164 573933118 2566387...

output:

49954742111708

result:

ok single line: '49954742111708'

Test #5:

score: 0
Accepted
time: 163ms
memory: 75144kb

input:

200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...

output:

100000000000000

result:

ok single line: '100000000000000'

Test #6:

score: 0
Accepted
time: 156ms
memory: 77312kb

input:

200000
274771488 823198191 332419028 866914185 137030479 445861162 505221814 805396419 842179806 540452002 510333908 765762441 345734318 975440944 186438657 676989478 108190396 339715111 337119327 462480232 634226928 438891079 609658471 156142766 16523966 699505629 190085420 960768051 824783291 5029...

output:

49967269431852

result:

ok single line: '49967269431852'

Test #7:

score: 0
Accepted
time: 284ms
memory: 77392kb

input:

200000
543681210 962563205 250397700 268525543 975554886 624102999 997517472 902158917 972202292 861887640 35775032 260723190 581651070 908449029 920192222 562166727 71415077 442629695 247231608 726904965 155868789 579129175 301712168 760082974 11645034 552993020 532073045 440207656 810726266 150259...

output:

33304730166370

result:

ok single line: '33304730166370'

Test #8:

score: 0
Accepted
time: 167ms
memory: 74912kb

input:

199998
689913610 725385763 163484638 868994205 449858903 631765674 574347626 260863034 740441133 55535165 612711113 42693300 91469451 459079704 241970526 395707182 581503675 186168355 536621457 878005967 776375657 311683657 643727441 342258990 29883737 50215092 771277858 346123680 93534188 401651778...

output:

49871887186423

result:

ok single line: '49871887186423'

Test #9:

score: 0
Accepted
time: 160ms
memory: 75136kb

input:

199999
105379362 923915615 215200323 953973925 78641957 232880810 918464290 933150426 311608001 159423490 707314389 967885525 479000867 35207303 644433637 193664828 4262237 382322834 849172685 887758838 699247657 92331957 549213389 480500907 257190920 229226021 152614682 98166290 186656024 866087158...

output:

50074806153680

result:

ok single line: '50074806153680'

Test #10:

score: 0
Accepted
time: 298ms
memory: 75460kb

input:

199999
657143391 45666910 758637402 727254629 218608391 985079369 439610506 817090643 927202721 486739391 516136382 282109517 220802622 390616397 850701405 967156836 100821917 627827474 93574692 820094865 60293196 308305441 661279124 464897166 824130309 998638602 843728821 402660293 852360018 864579...

output:

33311529559302

result:

ok single line: '33311529559302'

Test #11:

score: 0
Accepted
time: 4ms
memory: 20076kb

input:

1
49
60

output:

49

result:

ok single line: '49'

Test #12:

score: 0
Accepted
time: 202ms
memory: 77260kb

input:

199911
85073 1612357 1117052 2574297 2436828 222840 2319502 591643 2319425 180085 129090 1754039 1524000 590792 1313199 991385 2882348 2917574 2356578 2376276 1232750 2736131 3254231 1294377 1379116 1164673 1623200 1694383 2319482 2625088 2028684 2640741 1977127 3289737 1144951 2917936 362582 105848...

output:

168896977958

result:

ok single line: '168896977958'

Test #13:

score: 0
Accepted
time: 170ms
memory: 74984kb

input:

200000
142327150 513430292 906769950 518151702 849238647 155501711 925373625 222087519 417768102 614559622 809144615 727176011 108955247 243279471 691459975 22633211 727045283 931086253 49092450 115601776 667512127 670752015 471332788 474444363 633117334 790426364 431200432 208453449 919605053 13528...

output:

49997566595072

result:

ok single line: '49997566595072'

Test #14:

score: 0
Accepted
time: 183ms
memory: 75760kb

input:

199997
6999946 194430278 108816897 80696400 310045386 149673615 188623556 419014404 64078835 48842951 223647975 390286195 244417721 261759561 60310580 150670599 14722383 326063 42928058 221116909 161453531 140151053 296965067 247014569 11645014 413924829 172760189 345315367 55227980 280488862 586801...

output:

21025271981534

result:

ok single line: '21025271981534'

Test #15:

score: 0
Accepted
time: 308ms
memory: 74820kb

input:

200000
793895460 939042903 605004391 428355307 120383808 596587064 693444786 518489765 515441460 212695431 48914267 424096848 829856067 653560354 794365628 657155054 981570419 970104732 677694650 512172466 858817525 359974649 854988411 222801425 262743476 365072406 906324817 928141279 126786652 4513...

output:

21851360103579

result:

ok single line: '21851360103579'

Test #16:

score: 0
Accepted
time: 293ms
memory: 74828kb

input:

200000
92405740 230051343 94698482 917557300 124131769 361499357 976694091 463559129 258317776 704526053 192033713 338799970 398554963 909096457 56761970 864962722 971953118 495761835 350934210 465936906 524944026 887387114 856399250 359738396 947522411 693550385 904383383 844558602 328780170 752863...

output:

38847359292701

result:

ok single line: '38847359292701'

Test #17:

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

input:

2
7 76
10 89

output:

76

result:

ok single line: '76'

Test #18:

score: 0
Accepted
time: 296ms
memory: 75548kb

input:

200000
244021017 875612675 432728994 23711122 312320097 383983148 216608030 114030470 402878743 9332136 232199219 423620935 448837640 316651064 385864803 244577888 106045090 721508192 495447244 339623310 379106434 110632630 146087920 119129349 29487037 578664996 657979959 781106267 488587591 3036138...

output:

33330773164506

result:

ok single line: '33330773164506'

Test #19:

score: 0
Accepted
time: 160ms
memory: 75864kb

input:

200000
445744654 443694652 921312513 486929743 451137133 706037450 579745155 766897701 267962088 355969746 6465340 438890371 465601418 736566159 493336392 973448005 813018735 905271257 137892756 209739569 673165795 305571934 330150126 879561606 620421487 485540368 561206289 698815389 82869758 287991...

output:

50049229605683

result:

ok single line: '50049229605683'

Test #20:

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

input:

2
7 76
89 10

output:

17

result:

ok single line: '17'

Test #21:

score: 0
Accepted
time: 297ms
memory: 75876kb

input:

199999
793242061 669342146 543588608 882891106 341176229 958125367 784590587 139209586 530371510 715692132 870391324 832904085 565576613 606908811 917421250 711562465 854058638 465241186 478398164 660942120 919175606 477502123 716706138 330975221 141043582 139500841 711510209 904874680 714386666 588...

output:

33348117751480

result:

ok single line: '33348117751480'

Test #22:

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

input:

199989
89926964 182799389 183179415 120868578 195641603 193430072 119513695 37533839 114610519 133705816 3321649 67400788 199548630 110795787 46034038 99459241 71794114 162441770 61356634 101391579 676001 161319751 1074131 19850785 110548536 43687098 188514776 114550199 36040921 193647232 43232632 1...

output:

10153136627887

result:

ok single line: '10153136627887'

Test #23:

score: 0
Accepted
time: 252ms
memory: 77280kb

input:

200000
148167 937407 1724322 93836 1212638 561839 459101 1770455 636776 1430291 46270 1538313 71425 858941 479696 455959 1790564 1754423 1643683 1183121 1623556 58960 985460 1213628 492013 1603038 742006 319207 1121661 638507 1544626 1026953 285473 560993 1814313 1252825 358500 1864370 608666 143457...

output:

100188447201

result:

ok single line: '100188447201'

Test #24:

score: 0
Accepted
time: 249ms
memory: 75724kb

input:

199999
442551444 912392223 324603571 938425264 949530237 18894904 950855761 691012143 106328253 748915991 748343481 221457635 154734228 51263445 302354447 834989226 2082124 173637319 244185082 12789807 54002379 307343711 190690720 378387054 890668393 806027136 958028546 902508699 94632159 889239615 ...

output:

47532009537959

result:

ok single line: '47532009537959'

Test #25:

score: 0
Accepted
time: 169ms
memory: 77324kb

input:

199982
102522751 30277595 190549652 71219507 197763228 48621002 151446912 202479087 169304461 164438266 179496311 159889010 92336655 59122107 85056193 178336405 29425174 138439101 179568090 162169806 184038655 51992608 78868851 106412878 145527831 80681312 138150653 114472742 153904803 98480569 5935...

output:

10299356204318

result:

ok single line: '10299356204318'

Test #26:

score: 0
Accepted
time: 163ms
memory: 74784kb

input:

200000
73801034 347281304 283573375 389939508 358430052 90329268 894017257 174336980 332009492 856529136 601932136 880949401 324762153 764777799 110843668 178114056 653340678 654852069 284237074 377794799 991663598 575628958 947879999 72107494 459600466 64341501 65189918 573985855 785047220 81419991...

output:

50121681200274

result:

ok single line: '50121681200274'

Test #27:

score: 0
Accepted
time: 177ms
memory: 75860kb

input:

199989
113194381 18453124 39197171 98397543 45824456 95978171 103207468 23963206 96708868 91858539 125669636 29727287 45641460 183601442 98544899 149665561 122600831 127873364 56083730 177285601 173773998 98397724 40235628 162198786 129762866 137490430 131427272 1304290 143019726 154547489 153595991...

output:

10202456232461

result:

ok single line: '10202456232461'

Test #28:

score: 0
Accepted
time: 163ms
memory: 77404kb

input:

199999
960158369 810645963 431764335 710241238 650235958 274350815 97668804 360540767 980928506 256853239 106090204 618131257 272043818 632096020 447638357 406760186 23066426 881025543 315693732 882749165 324384940 265611873 582033714 297534692 137582097 429674820 971965089 388908340 501451208 45700...

output:

50030092692837

result:

ok single line: '50030092692837'

Extra Test:

score: 0
Extra Test Passed