QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650122 | #5069. Vacation | sunkaihuan | AC ✓ | 1011ms | 73684kb | C++14 | 5.4kb | 2024-10-18 13:11:52 | 2024-10-18 13:11:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
typedef long long ll;
int n,q,c,a[N];
ll pr[N],nx[N],id[N];
struct sgt1{
struct st{
ll lmx,rmx,mx,sum;
}t[N<<2];
void pushup(st &p,st p1,st p2){
p.sum=p1.sum+p2.sum;
p.mx=max({p1.mx,p2.mx,p1.rmx+p2.lmx});
p.lmx=max(p1.lmx,p2.lmx+p1.sum);
p.rmx=max(p2.rmx,p1.rmx+p2.sum);
}
void build(int p,int l,int r){//cout<<p<<" "<<l<<" "<<r<<"\n";
if(l==r){t[p].mx=t[p].lmx=t[p].rmx=t[p].sum=a[l];return;}
int mid=(l+r)>>1;build(p*2,l,mid),build(p*2+1,mid+1,r);pushup(t[p],t[p*2],t[p*2+1]);
}
void ch(int p,int l,int r,int pt,int v){
if(l==r){t[p].mx=t[p].lmx=t[p].rmx=t[p].sum=v;return;}int mid=(l+r)>>1;
if(pt<=mid)ch(p*2,l,mid,pt,v);else ch(p*2+1,mid+1,r,pt,v);pushup(t[p],t[p*2],t[p*2+1]);
}
st ask(int p,int l,int r,int ll,int rr){
if(ll<=l&&r<=rr)return t[p];int mid=(l+r)>>1;st res;
if(rr<=mid)return ask(p*2,l,mid,ll,rr);
if(ll>mid)return ask(p*2+1,mid+1,r,ll,rr);
pushup(res,ask(p*2,l,mid,ll,rr),ask(p*2+1,mid+1,r,ll,rr));
return res;
}
}t1;
struct sgt2{
struct st{
ll sum[2],tg[2],mx;
}t[N<<2];
void pushup(st &p,st p1,st p2){
p.sum[0]=max(p1.sum[0],p2.sum[0]);
p.sum[1]=max(p1.sum[1],p2.sum[1]);
p.mx=max({p1.mx,p2.mx,p1.sum[0]+p2.sum[1]});
}
void pushdown(int p){
if(t[p].tg[0]!=0){
t[p*2].sum[0]+=t[p].tg[0];t[p*2+1].sum[0]+=t[p].tg[0];
t[p*2].tg[0]+=t[p].tg[0];t[p*2+1].tg[0]+=t[p].tg[0];
t[p*2].mx+=t[p].tg[0],t[p*2+1].mx+=t[p].tg[0];t[p].tg[0]=0;
}
if(t[p].tg[1]!=0){
t[p*2].sum[1]+=t[p].tg[1];t[p*2+1].sum[1]+=t[p].tg[1];
t[p*2].tg[1]+=t[p].tg[1];t[p*2+1].tg[1]+=t[p].tg[1];
t[p*2].mx+=t[p].tg[1],t[p*2+1].mx+=t[p].tg[1];t[p].tg[1]=0;
}
}
void build(int p,int l,int r){
if(l==r){
t[p].sum[0]=pr[l],t[p].sum[1]=nx[l];
t[p].tg[0]=t[p].tg[1]=0;t[p].mx=-4000000000000000000ll;return;
}int mid=(l+r)>>1;build(p*2,l,mid),build(p*2+1,mid+1,r);
pushup(t[p],t[p*2],t[p*2+1]);//cerr<<p<<" "<<l<<" "<<r<<" "<<t[p].mx<<" "<<t[p].sum[0]<<" "<<t[p].sum[1]<<"\n";
}
void add(int p,int l,int r,int ll,int rr,long long v,int w){
if(ll<=l&&r<=rr){t[p].mx+=v,t[p].sum[w]+=v,t[p].tg[w]+=v;return;}int mid=(l+r)>>1;pushdown(p);
if(ll<=mid)add(p*2,l,mid,ll,rr,v,w);if(rr>mid)add(p*2+1,mid+1,r,ll,rr,v,w);pushup(t[p],t[p*2],t[p*2+1]);
}
st ask(int p,int l,int r,int ll,int rr){//cerr<<p<<" "<<l<<" "<<r<<" "<<ll<<" "<<rr<<"\n";
if(ll<=l&&r<=rr){return t[p];}
int mid=(l+r)>>1;pushdown(p);st res;
if(rr<=mid)return ask(p*2,l,mid,ll,rr);
if(ll>mid)return ask(p*2+1,mid+1,r,ll,rr);
pushup(res,ask(p*2,l,mid,ll,rr),ask(p*2+1,mid+1,r,ll,rr));
return res;
}
}t2;
struct sgt3{
ll mx[N<<2];
void pushup(int p){mx[p]=max(mx[p*2],mx[p*2+1]);}
void ch(int p,int l,int r,int pt,ll v){
if(l==r){mx[p]=v;return;}int mid=(l+r)>>1;
if(pt<=mid)ch(p*2,l,mid,pt,v);
else ch(p*2+1,mid+1,r,pt,v);pushup(p);
}
ll ask(int p,int l,int r,int ll,int rr){
if(ll<=l&&r<=rr)return mx[p];int mid=(l+r)>>1;
if(rr<=mid)return ask(p*2,l,mid,ll,rr);
if(ll>mid)return ask(p*2+1,mid+1,r,ll,rr);
return max(ask(p*2,l,mid,ll,rr),ask(p*2+1,mid+1,r,ll,rr));
}
}t3,t4;
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cin>>n>>q>>c;
for(int i=1;i<=n;i++)cin>>a[i];n++;
while(n%c)n++;t1.build(1,1,n);//cout<<n<<"\n";
for(int i=1;i<=n;i++)id[i]=(i-1)/c+1;
for(int i=c+1;i<=n;i++){
if(id[i]!=id[i-1])pr[i-c]=0;
else pr[i-c]=pr[i-c-1];pr[i-c]+=a[i];//,cerr<<pr[i-c]<<"\n";
}
for(int i=n-c;i>=1;i--){
if(id[i]!=id[i+1])nx[i]=0;
else nx[i]=nx[i+1];nx[i]+=a[i];//,cerr<<nx[i]<<"\n";
}
t2.build(1,1,n-c);//cerr<<t2.ask(1,1,n-c,2,4).mx<<"\n";
for(int i=1;i<=n;i+=c){//cout<<t1.ask(1,1,n,i,i+c-1).mx<<"\n";
t3.ch(1,1,n/c,(i-1)/c+1,t1.ask(1,1,n,i,i+c-1).mx);
if(i<=n-1)t4.ch(1,1,n/c-1,(i-1)/c+1,t2.ask(1,1,n-c,i,i+c-1).mx);
}
int op,x,y;ll ans;
for(int i=1;i<=q;i++){
cin>>op>>x>>y;
if(op==1){
if(id[x]>1)t2.add(1,1,n-c,x-c,id[x]*c-c,y-a[x],0),
t4.ch(1,1,n/c-1,id[x]-1,t2.ask(1,1,n-c,id[x]*c-c-c+1,id[x]*c-c).mx);//,cout<<t2.ask(1,1,n-c,id[x]*c-c-c+1,id[x]*c-c).mx<<"\n";
if(id[x]<n/c)t2.add(1,1,n-c,id[x]*c-c+1,x,y-a[x],1),
t4.ch(1,1,n/c-1,id[x],t2.ask(1,1,n-c,id[x]*c-c+1,id[x]*c).mx);
t1.ch(1,1,n,x,y);a[x]=y;
t3.ch(1,1,n/c,id[x],t1.ask(1,1,n,id[x]*c-c+1,id[x]*c).mx);
}
else{ans=0;//if(c==5)cout<<x<<" "<<y<<"\n";
if(y-x+1<=c)ans=max(ans,t1.ask(1,1,n,x,y).mx);
else if(id[x]==id[y]-1){
ans=max(ans,t2.ask(1,1,n-c,x,y-c).mx);//if(c==1)assert(ans==0);
ans=max(ans,t1.ask(1,1,n,x,x+c-1).mx);
ans=max(ans,t1.ask(1,1,n,y-c+1,y).mx);
}
else{
if(id[y]-id[x]>2){
ans=max(ans,t4.ask(1,1,n/c-1,id[x]+1,id[y]-2));
//if(c==1)assert(ans==0);
}
ans=max(ans,t3.ask(1,1,n/c,id[x]+1,id[y]-1));//cout<<ans<<'\n\n';
ans=max(ans,t2.ask(1,1,n-c,x,id[x]*c).mx);
// if(c==1)assert(t2.ask(1,1,n-c,x,id[x]*c).mx<0);
ans=max(ans,t1.ask(1,1,n,x,x+c-1).mx);
ans=max(ans,t2.ask(1,1,n-c,id[y]*c-c-c+1,y-c).mx);
// if(c==1)assert(t2.ask(1,1,n-c,id[y]*c-c+1,y).mx<0);
ans=max(ans,t1.ask(1,1,n,y-c+1,y).mx);
}
cout<<ans<<"\n";
}
}return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13860kb
input:
5 6 3 0 -5 -3 8 -3 2 3 5 1 2 5 2 1 5 1 4 -3 2 3 5 2 1 5
output:
8 10 0 5
result:
ok 4 number(s): "8 10 0 5"
Test #2:
score: 0
Accepted
time: 901ms
memory: 67432kb
input:
200000 500000 1 387060158 961744470 37167782 737122872 -532977662 1604246 -30977399 871848791 444997246 454204578 -813187501 -660394286 448014171 -835115276 -631880452 887715308 258530352 805589560 -414653327 -156732249 -335096199 -80266237 367896009 738406627 -903652056 446120866 415658444 -1347916...
output:
999902477 999981999 999343404 999847372 999957587 998160312 999981999 999981999 999981999 999980061 999981999 999981999 999981999 999876122 999981999 999996602 999981999 999981999 999981999 999723649 999981999 999957587 999896087 999981999 999981999 999981999 999981999 999981999 999957587 999981999 ...
result:
ok 250051 numbers
Test #3:
score: 0
Accepted
time: 895ms
memory: 63812kb
input:
200000 500000 5 802774074 383481934 -295470374 285359286 751657057 197444479 626916547 -828168464 288373833 -493446966 -208422769 956745384 919286225 959643271 -176531848 -380256966 357111771 -50890039 -637284768 -337010918 259019684 752475630 -259898780 98620995 -704832505 -532710796 -971600790 -84...
output:
4544135313 4544135313 4443416295 3390067591 4544135313 4544135313 4322308420 4386413596 4386413596 4165697630 4322308420 4287938127 4443416295 4544135313 4386413596 4165697630 4386413596 4386413596 4386413596 4323325838 4443416295 4386413596 4385851999 4544135313 4443416295 4443416295 4323325838 432...
result:
ok 249998 numbers
Test #4:
score: 0
Accepted
time: 832ms
memory: 58164kb
input:
200000 500000 10 294669347 -694582751 -596596961 -126098203 564639690 -654836388 -393227122 -835904658 699214733 147549986 -60745155 364274902 6365735 182107449 544381751 8255910 -581710335 -254751705 -547803021 113792037 -526424167 -948294769 -456727013 -172857504 627985189 -660230969 -233539222 -3...
output:
6382761194 6975829216 5771846079 7795537121 6975829216 7251135307 7795537121 7795537121 7795537121 7251135307 6382761194 7251135307 7795537121 7795537121 7251135307 6166320975 7251135307 5845186875 6304374419 7795537121 6533205084 6975829216 7795537121 6051983693 7795537121 6533205084 6671392380 553...
result:
ok 249912 numbers
Test #5:
score: 0
Accepted
time: 874ms
memory: 57716kb
input:
200000 500000 50 682924062 -410171362 727046928 -248951706 447030590 -828489266 -766563199 -502548010 -959695696 -583569857 -305162329 -550851997 -462615752 -822803313 -640012170 267251148 340565257 -111341766 689672874 -515868601 -242875719 -162422332 49211711 277849676 -108078900 -304560362 -50058...
output:
15856525974 15423765469 15423765469 15728637453 15856525974 15728637453 15728637453 15060577990 15856525974 15856525974 15060577990 15856525974 15856525974 15856525974 15060577990 15728637453 15856525974 15856525974 15856525974 15856525974 15592293852 15856525974 15592293852 15856525974 15423765469 ...
result:
ok 249945 numbers
Test #6:
score: 0
Accepted
time: 979ms
memory: 57040kb
input:
200000 500000 100 -861625642 488714758 151701153 337144530 -318293290 -765334091 -210261967 -253541961 993816332 -736017816 52189861 -428475798 -281280689 875335671 889366119 -863352867 4083578 382040499 152212580 696548442 348806166 -403452187 -91390158 -86542614 -915521115 -615218473 374313280 -60...
output:
22356669163 16483275109 20675548507 20675548507 18341749229 16758974141 19886103941 22356669163 12776363397 19919404941 22356669163 22356669163 22356669163 20675548507 22356669163 22356669163 20675548507 22356669163 19886103941 20352085144 22356669163 22356669163 19064838381 19782436621 20675548507 ...
result:
ok 250001 numbers
Test #7:
score: 0
Accepted
time: 1011ms
memory: 57716kb
input:
200000 500000 500 560111824 156076602 -300062433 -135130960 172514238 -107440145 332810571 -462042876 -248802506 163714210 -330670470 42796256 -486522143 -669315725 -916663241 992138762 904514188 -430525531 509990997 -414368382 886580739 968753025 -783053293 60399434 -189320070 -2477706 -334706343 4...
output:
51487237399 38429372430 32781696692 35966554114 51487237399 51487237399 49119655459 40039498632 49119655459 42076835781 51487237399 42076835781 40039498632 51487237399 40039498632 51487237399 43222631363 40936887546 38671383728 35611226388 42076835781 51487237399 51487237399 51487237399 35611226388 ...
result:
ok 249987 numbers
Test #8:
score: 0
Accepted
time: 978ms
memory: 56852kb
input:
200000 500000 1000 -274863070 -196927487 -173462836 -322148327 -974733923 872416187 81984586 243765318 392194447 16424530 -680051160 -870124234 197884950 51597873 -580027867 53316656 943742315 -289166281 665826659 505220474 -814189661 771924792 945468209 -606782872 -316840243 735583862 163401810 -98...
output:
68585884487 68585884487 68585884487 48732425297 68585884487 68585884487 34196859335 68585884487 44187544054 68585884487 59171503971 45112394103 48732425297 68585884487 68585884487 62264064415 68585884487 68585884487 68585884487 68585884487 68585884487 68585884487 62264064415 68585884487 44187544054 ...
result:
ok 249847 numbers
Test #9:
score: 0
Accepted
time: 936ms
memory: 57440kb
input:
200000 500000 5000 -233541473 -821406097 -834373426 -682847219 -558452214 794047404 658431025 584854890 -43958103 -471082436 456699444 660894280 -563936020 867203954 -26065334 680624954 844062461 -808600596 -206923771 788768922 266650071 -722136485 -308857317 414063248 333797658 468533943 -346326422...
output:
111528324186 111528324186 122473166396 88429113651 121592699866 90259744634 22840599473 111528324186 111528324186 121592699866 111528324186 111528324186 121592699866 88429113651 39504491251 121848200792 52521769508 97463661530 111528324186 35002189953 121848200792 98152563998 60222302625 29889397997...
result:
ok 249934 numbers
Test #10:
score: 0
Accepted
time: 986ms
memory: 57544kb
input:
200000 500000 10000 665344648 603248129 584747190 794918694 -495297038 -649651364 907437075 243399623 -196406062 424326840 284108349 842229343 891113172 396582242 895208153 639110569 -419465483 653939112 -456449644 -619549194 320587509 -619648562 -968216902 -393378967 -271827747 -656563637 194138895...
output:
56259543721 45446857386 127693546205 139657304562 139734032583 145066327195 151709822656 151709822656 151709822656 59196591326 151709822656 151709822656 151709822656 93441101388 145765337767 151709822656 151709822656 139657304562 139657304562 76339935235 82918361465 145765337767 152180432737 1521804...
result:
ok 249995 numbers
Test #11:
score: 0
Accepted
time: 713ms
memory: 57728kb
input:
200000 500000 50000 575796283 151484543 -720552679 -957363572 -132370386 -401546120 455846368 -409284627 408358670 41466509 998470195 393898097 -115481139 -871390033 993789573 -165491528 819845991 -936404970 189543742 213192673 -602174573 740565806 -821274853 332822078 340913021 634416742 950042524 ...
output:
34822696696 304044933300 68367040267 189494218463 334878403626 267659551435 24069522488 207246743747 266472736311 256136296058 318863343332 266472736311 318863343332 333342852149 333342852149 333342852149 333342852149 333342852149 244890005888 333894397388 14926116799 327180309259 169083865298 30229...
result:
ok 249979 numbers
Test #12:
score: 0
Accepted
time: 552ms
memory: 73684kb
input:
200000 500000 100000 569636990 278084140 -907570046 -104611731 552518652 -409282313 -595255647 231712326 556036284 -307914181 -157540087 -678605019 67375374 -777844451 54967467 -421230696 909327738 924463398 814165304 217454981 -504035512 469087307 268453049 448391697 -626058118 -867475106 -71503492...
output:
183803743045 84753846309 183803743045 184110002817 105439165831 67546271314 169297374450 99805942710 169297374450 182981361171 104276266099 264432291020 151095250825 264578163447 113845850587 185483046361 197245535689 185483046361 171141245411 163740444589 46081034455 99805942710 151095250825 171141...
result:
ok 249890 numbers
Test #13:
score: 0
Accepted
time: 388ms
memory: 70108kb
input:
200000 500000 200000 -797962146 -508688404 710511327 -513510680 728213176 552511953 -936241431 488159917 -444295562 -536695906 -505756916 130939739 614047261 -713095641 846308813 714302364 -50331832 62015532 -201658784 708890384 -759229325 -444174649 718951299 -388948828 877697837 -860392893 5422631...
output:
13912697561 53056934566 408059533397 26752612529 231772401996 408919427178 79448528167 268531947957 134457596821 132829174449 109465830672 94113395976 408210605035 408210605035 408210605035 79283848538 409284836395 75674809566 231092415035 90163884680 99205202539 269241228577 106739591025 1438823581...
result:
ok 249963 numbers