QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698335 | #4897. 音符大师 | cjx | 15 | 172ms | 116220kb | C++14 | 5.3kb | 2024-11-01 18:58:34 | 2024-11-01 18:58:34 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long read(){
long long x=0,f=1;char ch=getchar();
while(!isdigit(ch))
{if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void write(long long x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
bool M1;
const int N=1e5+10,nL=55,M=1.7e7;
const ll inf=1e15;
int n,l0,tb;
bool tiao=0;
ll pi[N];
ll b[N];
int tot,rt[N][nL];
#define pl a[p].tl
#define pr a[p].tr
struct Segment{
struct Node{
int tl,tr;
ll mx,mxl,mxr,tag;
}a[M];
int nc[M];
Segment(){
for(int i=0;i<M;i++)nc[i]=i;
}
void pushup(int p){
a[p].mx=min(a[pl].mx,a[pr].mx);
a[p].mxl=min(a[pl].mxl,a[pr].mxl);
a[p].mxr=min(a[pl].mxr,a[pr].mxr);
}
void make(int &p){
if(!p)a[p=nc[++tot]]=a[0];
}
void del(int &p){
if(!p)return;
nc[tot--]=p;
p=0;
}
void pushdown(int p){
if(a[p].tag){
if(pl){
a[pl].mx+=a[p].tag;a[pl].tag+=a[p].tag;
a[pl].mxl+=a[p].tag;a[pl].mxr+=a[p].tag;
}
if(pr){
a[pr].mx+=a[p].tag;a[pr].tag+=a[p].tag;
a[pr].mxl+=a[p].tag;a[pr].mxr+=a[p].tag;
}
a[p].tag=0;
}
}
void change(int p,int x,ll v,int L=1,int R=tb){
if(!p)return;
if(L==R){
a[p].mx=min(a[p].mx,v);
a[p].mxl=a[p].mx-b[L];a[p].mxr=a[p].mx+b[L];
return;
}
int mid=(L+R)>>1;
if(x<=mid)make(pl);
if(x>mid)make(pr);
pushdown(p);
if(x<=mid)change(pl,x,v,L,mid);
else change(pr,x,v,mid+1,R);
pushup(p);
}
void update(int p,int l,int r,ll v,int L=1,int R=tb){
if(!p||l>r)return;
if(l<=L&&R<=r){
a[p].tag+=v;a[p].mx+=v;a[p].mxl+=v;a[p].mxr+=v;
return;
}
//make(pl);
//make(pr);
pushdown(p);
int mid=(L+R)>>1;
if(l<=mid)update(pl,l,r,v,L,mid);
if(r>mid)update(pr,l,r,v,mid+1,R);
pushup(p);
}
ll ask(int p,int l,int r,int ty,int L=1,int R=tb){
if(!p||l>r)return inf;
if(l<=L&&R<=r){
if(ty==0)return a[p].mx;
if(ty==1)return a[p].mxl;
return a[p].mxr;
}
pushdown(p);
int mid=(L+R)>>1;
ll ans=inf;
if(l<=mid)ans=min(ans,ask(pl,l,r,ty,L,mid));
if(r>mid)ans=min(ans,ask(pr,l,r,ty,mid+1,R));
return ans;
}
int merge(int p,int q,int L=1,int R=tb){
if(!p||!q)return p+q;
if(L==R){
a[p].mx=min(a[p].mx,a[q].mx);
a[p].mxl=min(a[p].mxl,a[q].mxl);
a[p].mxr=min(a[p].mxr,a[q].mxr);
del(q);
return p;
}
pushdown(p);pushdown(q);
int mid=(L+R)>>1;
pl=merge(pl,a[q].tl,L,mid);
pr=merge(pr,a[q].tr,mid+1,R);
pushup(p);
del(q);
return p;
}
void dfs(int p,int L=1,int R=tb){
if(!p)return;
if(L==R){
printf("p=%d [%d,%d] mx=%lld %lld %lld\n",p,L,R,a[p].mx,a[p].mxl,a[p].mxr);
return;
}
make(pl);make(pr);
pushdown(p);
int mid=(L+R)>>1;
dfs(pl,L,mid);dfs(pr,mid+1,R);
}
}tre;
bool M2;
int main(){
//double sts=clock();
//freopen("game.in","r",stdin);
//freopen("game.out","w",stdout);
//printf("%.3lf MB\n",(&M1-&M2)/1024.0/1024.0);
tre.a[0].mx=tre.a[0].mxl=tre.a[0].mxr=inf;
n=read();l0=read();
b[++tb]=0;
for(int i=1;i<=n;i++){
pi[i]=read();
b[++tb]=pi[i];
b[++tb]=max(0ll,pi[i]-l0);
}
sort(b+1,b+tb+1);
tb=unique(b+1,b+tb+1)-b-1;
tre.make(rt[0][0]);
tre.change(rt[0][0],1,0);
for(int i=0;i<n;i++){
for(int j=0;j<=l0;j++){
if(!rt[i][j])continue;
int l1=lower_bound(b+1,b+tb+1,max(0ll,pi[i+1]-l0))-b;
int r1=lower_bound(b+1,b+tb+1,pi[i+1])-b;
int il=pi[i+1]-b[l1],ir=pi[i+1]-b[r1];
int now=lower_bound(b+1,b+tb+1,pi[i]-j)-b;
ll v1=tre.ask(rt[i][j],1,l1-1,1)+b[l1];//2 yi
if(!rt[i+1][il])tre.make(rt[i+1][il]);
tre.change(rt[i+1][il],now,v1);
ll v2=tre.ask(rt[i][j],r1+1,tb,2)-b[r1],v3;
if(!rt[i+1][ir])tre.make(rt[i+1][ir]);
tre.change(rt[i+1][ir],now,v2);
for(int k=l1;k<=r1;k++){
v3=tre.ask(rt[i][j],k,k,0);
if(v3>=inf)continue;
if(!rt[i+1][pi[i+1]-b[k]])tre.make(rt[i+1][pi[i+1]-b[k]]);
tre.change(rt[i+1][pi[i+1]-b[k]],now,v3);
}
//1 yi
if(now<l1){
tre.update(rt[i][j],1,tb,b[l1]-b[now]);
tre.merge(rt[i+1][il],rt[i][j]);
}
else if(now>r1){
tre.update(rt[i][j],1,tb,b[now]-b[r1]);
tre.merge(rt[i+1][ir],rt[i][j]);
}
else{
tre.merge(rt[i+1][pi[i+1]-b[now]],rt[i][j]);
}
if(tiao==1)puts("");
}
}
ll ans=inf;
for(int i=0;i<=l0;i++){
if(!rt[n][i])continue;
//printf("rt[%d][%d]=%d \n",n,i,rt[n][i]);
// tre.dfs(rt[n][i]);puts("");
ans=min(ans,tre.ask(rt[n][i],1,tb,0));
}
write(ans);puts("");
//printf("time=%.3lfs\n",(clock()-sts)/1000.0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 71748kb
input:
200 20 78 30 163 87 97 53 96 76 81 138 156 200 124 93 173 119 115 93 150 99 22 80 88 131 61 126 47 103 143 142 129 186 89 105 101 143 178 110 13 77 79 178 21 108 200 146 87 105 54 61 136 69 161 195 13 105 18 151 25 191 30 35 90 110 17 98 181 58 120 102 139 71 59 24 72 84 33 12 28 82 23 80 128 96 115...
output:
4433
result:
wrong answer 1st lines differ - expected: '3669', found: '4433'
Subtask #2:
score: 15
Accepted
Test #19:
score: 15
Accepted
time: 47ms
memory: 83304kb
input:
50000 0 957304147 455870042 888520405 388924006 685268286 213595280 898496267 50362797 310595209 105517171 706682592 663787741 927429771 306122736 1352192 453945549 31881610 943782347 779421515 543589796 209926777 908434673 845417119 374441290 190474943 606994057 30091060 491598457 644246786 4649716...
output:
7861788079227
result:
ok single line: '7861788079227'
Test #20:
score: 15
Accepted
time: 32ms
memory: 82028kb
input:
50000 0 267539818 976941407 232914453 134486565 946077774 327303661 383860856 427463180 82433525 829152030 323047687 114009885 572336732 324540200 312372486 904267355 354174716 897077585 726797234 14815480 56504568 128226636 908533574 690241784 234432089 60842581 4158447 140784062 814696061 27580609...
output:
7502844748010
result:
ok single line: '7502844748010'
Test #21:
score: 15
Accepted
time: 50ms
memory: 83480kb
input:
50000 0 113234313 300322176 223748251 154992665 988783374 705920968 587653430 735106433 339878986 23782050 772071399 43924374 333487655 112104185 388912725 30645653 230657785 50181507 210382459 974636263 84812430 683840330 470879024 352138490 544953829 857016921 83527213 679251552 204113040 48552509...
output:
7819216642612
result:
ok single line: '7819216642612'
Test #22:
score: 15
Accepted
time: 53ms
memory: 83024kb
input:
50000 0 57573834 735491176 585967317 50750966 13561867 538400010 923336660 411978534 229545007 608845964 778611980 433080482 340855878 525841885 436793984 121792438 646117967 157139578 341644163 71379300 980382262 841426801 263042095 570909388 241669384 780525526 306815843 529038526 677693926 272888...
output:
7502087871392
result:
ok single line: '7502087871392'
Test #23:
score: 15
Accepted
time: 47ms
memory: 83808kb
input:
50000 0 150529956 908563845 724316344 71839499 520290302 12371329 763161706 965762834 605485868 377855450 364159073 557572417 13573314 8085996 723464069 322060474 374561435 448408270 121729850 91335553 69989524 231531526 901985946 472906330 960997677 246590568 401537295 540808342 30457662 978645485 ...
output:
7655855679050
result:
ok single line: '7655855679050'
Test #24:
score: 15
Accepted
time: 48ms
memory: 82308kb
input:
50000 0 940144100 18386479 769788658 44738457 90257879 879207970 925016558 964597036 662771443 441833534 638630926 257398005 693370314 852807331 472327316 858562055 874978007 530679568 947674579 7081350 647463115 399061769 81471568 897044511 672282388 395480185 381093973 103836241 52060856 136053749...
output:
7329741440393
result:
ok single line: '7329741440393'
Test #25:
score: 15
Accepted
time: 57ms
memory: 82496kb
input:
50000 0 595877781 416920133 504115297 682623073 942495777 808743152 122852578 564363701 980818902 501483584 374724004 69557753 835258645 860520007 102814074 680949932 29792102 646922045 695269515 161539625 468996996 528287965 284414170 145379630 414176299 532680752 96308272 806611720 849878782 97734...
output:
7372386712114
result:
ok single line: '7372386712114'
Test #26:
score: 15
Accepted
time: 30ms
memory: 83420kb
input:
50000 0 236037002 215233133 41019240 229757515 806834959 849843304 862557844 39545138 297402862 7293515 880125105 285706647 152887583 198537021 740552834 3427605 366976152 641734017 106888137 154277089 259614856 518826105 796155721 132034997 420344028 702041117 117477828 821050418 113096425 2869065 ...
output:
7508382287165
result:
ok single line: '7508382287165'
Test #27:
score: 15
Accepted
time: 49ms
memory: 83300kb
input:
50000 0 428263671 324606118 736973623 961066097 320407929 663897387 328110400 789178775 344241539 34611323 77458169 730418405 89677130 456628708 735813218 665313790 99553725 408359166 161580926 95603740 537817168 587203140 239173276 980655467 73440384 209550435 242679387 923020102 447641965 71570611...
output:
7241590054407
result:
ok single line: '7241590054407'
Test #28:
score: 15
Accepted
time: 51ms
memory: 82740kb
input:
50000 0 848511669 673688847 134042037 382760566 86940474 283461772 923214109 543686174 579545679 713904091 366348707 242716930 5641588 704870794 542778347 296428822 959149832 495183306 649986132 551497587 550623110 591035272 204338017 214181048 891861232 524406707 448388519 594832891 610827442 93698...
output:
7606261035748
result:
ok single line: '7606261035748'
Test #29:
score: 15
Accepted
time: 51ms
memory: 83280kb
input:
50000 0 532965906 613164218 854565797 576587516 227406875 115434558 767691663 854474298 982611179 969491137 234543738 69267955 646968047 897911688 721008706 422527377 387136261 762884658 51918347 448273062 574144173 857719871 888425078 575352222 730868624 568669670 590036983 778842602 259437307 7201...
output:
7641479018806
result:
ok single line: '7641479018806'
Test #30:
score: 15
Accepted
time: 51ms
memory: 82320kb
input:
50000 0 950114012 924063984 78459732 2585137 167568618 422620546 817141675 939136111 912071559 28108367 138440975 401623398 614543476 413859636 583198666 7145092 692094019 896479223 265275914 14852033 553761091 831725889 256534067 178236755 434539705 610839223 807151106 140182765 324816595 576215181...
output:
7740448798710
result:
ok single line: '7740448798710'
Test #31:
score: 15
Accepted
time: 44ms
memory: 86500kb
input:
49983 0 500000001 500000002 500000003 500000004 500000005 499999994 499999993 499999992 500000009 500000010 499999989 500000012 499999987 499999986 499999985 500000016 500000017 500000018 500000019 500000020 500000021 499999978 500000023 500000024 500000025 499999974 499999973 500000028 500000029 50...
output:
1000099953
result:
ok single line: '1000099953'
Test #32:
score: 15
Accepted
time: 52ms
memory: 86756kb
input:
49993 0 499999999 500000002 499999997 500000004 500000005 500000006 500000007 499999992 500000009 500000010 500000011 500000012 500000013 499999986 500000015 499999984 500000017 500000018 500000019 500000020 499999979 499999978 500000023 499999976 500000025 499999974 500000027 500000028 500000029 50...
output:
1000099975
result:
ok single line: '1000099975'
Test #33:
score: 15
Accepted
time: 49ms
memory: 86080kb
input:
49973 0 500049973 499950028 500049971 499950030 500049969 499950032 499950033 500049966 499950035 499950036 499950037 500049962 499950039 499950040 499950041 499950042 499950043 499950044 500049955 500049954 500049953 499950048 500049951 499950050 499950051 500049948 500049947 499950054 499950055 50...
output:
1000099943
result:
ok single line: '1000099943'
Test #34:
score: 15
Accepted
time: 51ms
memory: 86652kb
input:
49915 0 500049915 500049914 500049913 500049912 500049911 500049910 500049909 499950092 499950093 499950094 500049905 499950096 499950097 499950098 500049901 499950100 499950101 500049898 499950103 500049896 500049895 499950106 499950107 500049892 500049891 499950110 499950111 500049888 500049887 50...
output:
1000099826
result:
ok single line: '1000099826'
Test #35:
score: 15
Accepted
time: 77ms
memory: 85872kb
input:
49988 0 498700312 495251235 501399608 499800060 498600448 503198912 504498380 498600532 496801280 503548509 497001320 501749195 500949544 502698650 495852158 497701242 499700168 500449739 495452730 495452821 504547088 502448383 503497620 497451785 500299784 495503330 503597264 501298986 496602720 49...
output:
38221665124
result:
ok single line: '38221665124'
Test #36:
score: 15
Accepted
time: 73ms
memory: 86348kb
input:
49980 0 861023239 819075173 824051456 830302098 868589663 916145572 954591723 979803571 998257840 22234729 68881831 35652996 8950761 967484878 964486638 940432553 916275761 928066101 896502131 848012777 841104435 861529167 903652074 939883118 940734108 981052781 951525008 994619188 22352207 1107682 ...
output:
1157487018739
result:
ok single line: '1157487018739'
Test #37:
score: 15
Accepted
time: 71ms
memory: 86144kb
input:
49966 0 852476251 835825994 822071673 774983009 726653125 713373455 725480626 715895559 671128277 642628571 609231701 621486354 601283796 615038192 639110541 641191588 672075707 707629014 738623890 760026457 798462033 833851537 853325404 870571810 895994097 899272379 889729666 849980053 859731156 88...
output:
1142099399674
result:
ok single line: '1142099399674'
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #38:
score: 30
Accepted
time: 94ms
memory: 82148kb
input:
50000 4 93134491 89313862 124691008 802991790 331181139 197882475 116544590 671508371 708702108 912388931 987332709 138451461 599145073 190259268 63842545 907913440 267186576 871474853 47940039 883678467 296713066 614786363 619945826 972153052 459383869 892979253 124879587 476608391 630338859 858860...
output:
7338303040315
result:
ok single line: '7338303040315'
Test #39:
score: 30
Accepted
time: 100ms
memory: 82348kb
input:
50000 1 96638807 189147065 74347926 612965597 159498115 520376727 864162547 386960972 1841563 23579014 841459605 190360986 45838400 126966900 810715480 516259775 628498591 450996564 824635091 191199182 700241024 756017147 898453918 459575879 426890959 156536209 838641385 443706026 903780865 17646152...
output:
7873102593653
result:
ok single line: '7873102593653'
Test #40:
score: 30
Accepted
time: 97ms
memory: 83848kb
input:
50000 3 745360608 6735019 431283376 145039802 119875030 534821831 511330018 42192384 712504933 492973126 387660190 443412044 862470236 177486601 36626719 81150268 142199882 368074119 618754811 636255109 596242962 917517654 121978010 983663165 913567353 971749349 982067690 55247161 315629402 66945700...
output:
7591258144793
result:
ok single line: '7591258144793'
Test #41:
score: 30
Accepted
time: 104ms
memory: 83504kb
input:
50000 3 909785500 107719407 318069881 30132374 913542 899787314 944462821 569659437 566966764 478591625 776395522 427509385 397305923 705750815 585678434 783539645 105125233 153346331 764397112 127662969 260383471 516911978 715693355 75372256 355611959 234089661 925485571 724156939 844155955 5579474...
output:
7654611376770
result:
ok single line: '7654611376770'
Test #42:
score: 30
Accepted
time: 90ms
memory: 82104kb
input:
50000 3 817491486 744544834 201771894 975700287 202953941 293706827 72833457 582412424 134081912 851615350 880436582 970075353 485596864 106763228 695788838 334990668 503306101 475283379 970547334 770296113 559220404 296077208 848119514 642248950 395387458 623113893 801147558 724656589 873969176 513...
output:
7766215327804
result:
ok single line: '7766215327804'
Test #43:
score: 30
Accepted
time: 113ms
memory: 83860kb
input:
50000 1 785978500 251022732 166749890 386374830 330342305 522259952 793082910 596058438 354463396 88093431 583592243 286599538 951600511 510492574 899538636 915986033 921928124 244193386 542662362 213466822 117679893 652597332 144638658 420876009 310028436 627505349 87022195 443333660 73013347 94190...
output:
7446402396820
result:
ok single line: '7446402396820'
Test #44:
score: 30
Accepted
time: 48ms
memory: 82128kb
input:
50000 0 667474806 215959392 331031022 911159820 343182517 944709355 353285692 320119388 373804004 142458765 262684988 263254603 911896911 313044076 347410912 539335702 421869709 106833706 268922920 306103357 552339157 88164278 550492175 694082174 722905335 576290373 132111700 537072659 882892968 905...
output:
7507689755772
result:
ok single line: '7507689755772'
Test #45:
score: 30
Accepted
time: 109ms
memory: 82988kb
input:
50000 3 721738851 376934408 891532071 449479121 488715717 559148237 467867683 30844659 57488220 172856656 362170970 66001996 720845454 891481466 740192981 249921871 539860934 64494424 182351571 730599134 197353795 470416736 404125359 120455586 196713216 514047403 904533551 85587408 911516187 8426054...
output:
7515161193147
result:
ok single line: '7515161193147'
Test #46:
score: 0
Wrong Answer
time: 172ms
memory: 116220kb
input:
49985 4 499999999 499999998 500000003 500000004 499999995 499999994 500000007 500000008 500000009 499999990 499999989 500000012 500000013 500000014 499999985 499999984 499999983 500000018 500000019 499999980 499999979 500000022 499999977 500000024 500000025 499999974 499999973 499999972 499999971 49...
output:
1000099950
result:
wrong answer 1st lines differ - expected: '1000099944', found: '1000099950'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%