QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#581361 | #9222. Price Combo | AllenJYL | AC ✓ | 572ms | 83720kb | C++14 | 5.3kb | 2024-09-22 12:17:39 | 2024-09-22 12:17:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ls p<<1
#define rs p<<1|1
#define msp(_array) memset(_array,0x3f,sizeof _array)
#define ms0(_array) memset(_array,0,sizeof _array)
#define msn(_array) memset(_array,-1,sizeof _array)
#define mc(_tar,_array) memcpy(_tar,_array,sizeof _tar)
#define pii pair<int,int>
#define endl '\n'
bool bg_memory;
const int mod=1e9+7;
const int inf=1e16;
const int bs=233;
const double eps=1e-6;
const int N=2e5+7,M=1e5+7;
inline void cmax(int &a,int b){a=a<b?b:a;}
inline void cmin(int &a,int b){a=a>b?b:a;}
inline int qp(int a,int b){int res=1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int n;
int a[N],b[N];
int oa[N],ob[N];
vector<int> v[N];
struct info{
int f[2];
void operator+=(int x){f[0]+=x;f[1]+=x;}
};
struct d{
int l,f[2];
info operator()(info x){return {x.f[l]+f[l^1],x.f[l^1]+f[l]};}
d operator*(d b){
return {l^b.l,f[b.l]+b.f[0],f[b.l^1]+b.f[1]};
}
};
info max(info a,info b){return {min(a.f[0],b.f[0]),min(a.f[1],b.f[1])};}
struct node{
d f;
info v[2];
int tg[2],t;
node operator+(node b){
node ans;
ans.tg[0]=ans.tg[1]=ans.t=0;
ans.f=f*b.f;
ans.v[0]=max(v[0],f(b.v[0]));
ans.v[1]=max(v[1],f(b.v[1]));
return ans;
}
node(){v[0].f[0]=v[0].f[1]=v[1].f[0]=v[1].f[1]=inf;}
};
struct sgt{
node t[N<<2];
void ut(int p){
t[p].t^=1;
std::swap(t[p].v[0],t[p].v[1]);
std::swap(t[p].tg[0],t[p].tg[1]);
}
void pushdown(int p){
if(t[p].t){
ut(ls);ut(rs);
t[p].t=0;
}
t[ls].v[0]+=t[p].tg[0];
t[ls].tg[0]+=t[p].tg[0];
t[rs].v[0]+=t[p].tg[0];
t[rs].tg[0]+=t[p].tg[0];
t[ls].v[1]+=t[p].tg[1];
t[ls].tg[1]+=t[p].tg[1];
t[rs].v[1]+=t[p].tg[1];
t[rs].tg[1]+=t[p].tg[1];
t[p].tg[0]=t[p].tg[1]=0;
}
void mdf(int p,int l,int r,int x,int y,info z){
if(l==r) return t[p].v[y]=z,void();
pushdown(p);
int mid=l+r>>1;
if(x<=mid) mdf(ls,l,mid,x,y,z);
else mdf(rs,mid+1,r,x,y,z);
t[p]=t[ls]+t[rs];
}
void upd(int p,int l,int r,int x,int y){
if(l==r) return t[p].f.l^=1,t[p].f.f[t[p].f.l]+=y,void();
pushdown(p);
int mid=l+r>>1;
if(x<=mid) upd(ls,l,mid,x,y);
else upd(rs,mid+1,r,x,y);
t[p]=t[ls]+t[rs];
}
void upd(int p,int l,int r,int ll,int rr,int x){
if(ll<=l&&rr>=r) return t[p].v[0]+=x,t[p].tg[0]+=x,void();
pushdown(p);
int mid=l+r>>1;
if(ll<=mid) upd(ls,l,mid,ll,rr,x);
if(rr>mid) upd(rs,mid+1,r,ll,rr,x);
t[p]=t[ls]+t[rs];
}
void swap(int p,int l,int r,int ll,int rr){
if(ll<=l&&rr>=r) return ut(p);
pushdown(p);
int mid=l+r>>1;
if(ll<=mid) swap(ls,l,mid,ll,rr);
if(rr>mid) swap(rs,mid+1,r,ll,rr);
t[p]=t[ls]+t[rs];
}
node ask(int p,int l,int r,int ll,int rr){
if(ll<=l&&rr>=r) return t[p];
pushdown(p);
int mid=l+r>>1;
if(rr<=mid) return ask(ls,l,mid,ll,rr);
if(ll>mid) return ask(rs,mid+1,r,ll,rr);
return ask(ls,l,mid,ll,rr)+ask(rs,mid+1,r,ll,rr);
}
}t;
mt19937 rnd(time(0));
int Case=1;
void Main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],oa[i]=i;
for(int i=1;i<=n;i++) cin>>b[i],ob[i]=i;
sort(oa+1,oa+n+1,[](int x,int y){return a[x]<a[y];});
sort(ob+1,ob+n+1,[](int x,int y){return b[x]<b[y];});
int tmp;
for(int i=1;i<=n;i++) tmp=a[oa[i]],a[oa[i]]=i,oa[i]=tmp;
for(int i=1;i<=n;i++) tmp=b[ob[i]],b[ob[i]]=i,ob[i]=tmp;
v[0].push_back(1);
for(int i=1;i<=n;i++) v[a[i]].push_back(b[i]);
for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
for(int i=1;i<=n+1;i++) t.mdf(1,1,n+1,i,0,{0,inf});
for(int i=n;i>=1;i--){
for(int j:v[i]){
t.upd(1,1,n+1,1,j,oa[i]);
t.swap(1,1,n+1,1,j);
t.upd(1,1,n+1,j,ob[j]);
}
for(int j:v[i-1]){
node tmp=t.ask(1,1,n+1,j,n+1);
t.mdf(1,1,n+1,j,0,tmp.v[0]);
t.mdf(1,1,n+1,j,1,tmp.v[1]);
}
}
node ans=t.ask(1,1,n+1,1,1);
cout<<min({ans.v[0].f[0],ans.v[0].f[1],ans.v[1].f[0],ans.v[1].f[1]})<<endl;
return;
}
string RdFile="";
int time_border,memory_border;
bool en_memory;
signed main(){
auto bg_clock=chrono::high_resolution_clock::now();
// freopen((RdFile+".in").c_str(),"r",stdin);
// freopen((RdFile+".out").c_str(),"w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
time_border=1000;
memory_border=256;
// cin>>Case;
while(Case--) Main();
auto en_clock=chrono::high_resolution_clock::now();
auto duration_clock=chrono::duration_cast<chrono::microseconds>(en_clock-bg_clock);
double duration_count=duration_clock.count()*0.001;
double memory_used=(&en_memory-&bg_memory)/1024.0/1024;
if(duration_count>0.2*time_border) cerr<<"TLwarning: "<<duration_count<<"/"<<time_border<<"ms"<<endl;
if(memory_used>0.8*memory_border) cerr<<"MLwarning: "<<memory_used<<"/"<<memory_border<<"MB"<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 76924kb
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: 76280kb
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: 461ms
memory: 83624kb
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: 457ms
memory: 83680kb
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: 399ms
memory: 83720kb
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: 454ms
memory: 83688kb
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: 565ms
memory: 83600kb
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: 457ms
memory: 83672kb
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: 452ms
memory: 83680kb
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: 572ms
memory: 83544kb
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: 0ms
memory: 76548kb
input:
1 49 60
output:
49
result:
ok single line: '49'
Test #12:
score: 0
Accepted
time: 475ms
memory: 83672kb
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: 455ms
memory: 83680kb
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: 473ms
memory: 83660kb
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: 546ms
memory: 83720kb
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: 551ms
memory: 83672kb
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: 4ms
memory: 75792kb
input:
2 7 76 10 89
output:
76
result:
ok single line: '76'
Test #18:
score: 0
Accepted
time: 556ms
memory: 83680kb
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: 453ms
memory: 83620kb
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: 7ms
memory: 75776kb
input:
2 7 76 89 10
output:
17
result:
ok single line: '17'
Test #21:
score: 0
Accepted
time: 558ms
memory: 83680kb
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: 477ms
memory: 83480kb
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: 460ms
memory: 83684kb
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: 511ms
memory: 83632kb
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: 454ms
memory: 83680kb
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: 460ms
memory: 83608kb
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: 470ms
memory: 83664kb
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: 460ms
memory: 83676kb
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