QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749477 | #7495. 世上最幸福的女孩 | TheZone | 0 | 0ms | 0kb | C++17 | 4.3kb | 2024-11-15 01:19:53 | 2024-11-15 01:19:54 |
answer
#include<cstdio>
#include<cctype>
#include<algorithm>
using std::sort;
using ll=long long;
namespace IO
{
char ibuf[(1<<21)+1],obuf[(1<<21)+1],st[21],*iS,*iT,*oS=obuf,*oT=obuf+(1<<21);
char Get(){return (iS==iT? (iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT? EOF:*iS++)):*iS++);}
void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
void Put(char x){*oS++=x;if(oS==oT)Flush();}
int read(){int x=0,c=Get(),f=1;while(!isdigit(c)&&c^'-')c=Get();if(c=='-')f=-1,c=Get();while(isdigit(c))x=x*10+c-48,c=Get();return f*x;}
void write(ll x){int top=0;if(x<0)Put('-'),x=-x;if(!x)Put('0');while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put('\n');}
}using IO::read;using IO::write;
const int N=300007,M=600007;const ll inf=1ll<<50;
ll max(const ll&a,const ll&b){return a>b? a:b;}
int n,m,cnt;ll tag,a[N],ans[M];
struct dot{ll x,y;};
dot operator+(const dot&a,const dot&b){return {a.x+b.x,a.y+b.y};}
dot operator-(const dot&a,const dot&b){return {a.x-b.x,a.y-b.y};}
int operator<(const dot&a,const dot&b){return a.y*b.x<=a.x*b.y;}
struct convex
{
dot *stk;int top,now;
dot&operator[](const int&x){return stk[x];}
void upd(const dot&a){stk[a.x].y=max(stk[a.x].y,a.y);}
void ins(const dot&a){stk[++top]=a;}
void clr(const int&n){for(int i=1;i<=n;++i)stk[i]={i,-inf};top=n;}
void build()
{
if(top<=2) return;
int i=3,n=top;top=2,now=1;
for(;i<=n;++i)
{
if(stk[i].y==-inf) continue;
while(top>1&&(stk[top]-stk[top-1])<(stk[i]-stk[top-1])) --top;
stk[++top]=stk[i];
}
}
ll cal(){while(now^top&&(-tag)*(stk[now+1].x-stk[now].x)<(stk[now+1].y-stk[now].y))++now;return tag*stk[now].x+stk[now].y;}
};
struct data{ll sum,pre,suf,ans;};
data operator+(const data&a,const data&b){return {a.sum+b.sum,max(a.pre,a.sum+b.pre),max(a.suf+b.sum,b.suf),max(max(a.ans,b.ans),a.suf+b.pre)};}
namespace segtree
{
#define ls p<<1
#define rs p<<1|1
#define mid ((l+r)>>1)
dot prep[20][M],sufp[20][M],ansp[20][M],*ppre[20],*psuf[20],*pans[20];
convex pre[N<<2],suf[N<<2],ans[N<<2];ll sum[N<<2];
void init(){for(int i=0;i<20;++i)ppre[i]=prep[i],psuf[i]=sufp[i],pans[i]=ansp[i];}
void merge(convex&c,convex&a,convex&b,const dot&p)
{
for(int i=1;i<=a.top;++i) c.ins(a[i]);
for(int i=1;i<=b.top;++i) c.ins(p+b[i]);
c.build();
}
void merge(convex&c,convex&a,convex&b)
{
int i=1,j=1;
c.upd(a[i]+b[j]);
while(i^a.top&&j^b.top) ((a[i+1]-a[i])<(b[j+1]-b[j])? j:i)++,c.upd(a[i]+b[j]);
while(i^a.top) ++i,c.upd(a[i]+b[j]);
while(j^b.top) ++j,c.upd(a[i]+b[j]);
}
void build(int p,int l,int r,int d)
{
pre[p].stk=ppre[d],suf[p].stk=psuf[d],ans[p].stk=pans[d];
if(r==l+1) pre[p][2]=suf[p][2]=ans[p][2]={1,sum[p]=a[r]},pre[p][1]=suf[p][1]=ans[p][1]={0,0},pre[p].top=suf[p].top=ans[p].top=2;
else
{
build(ls,l,mid,d+1),build(rs,mid,r,d+1);
sum[p]=sum[ls]+sum[rs],merge(pre[p],pre[ls],pre[rs],{mid-l,sum[ls]}),merge(suf[p],suf[rs],suf[ls],{r-mid,sum[rs]}),++ans[p].stk,ans[p].clr(r-l);
for(int i=1;i<=ans[ls].top;++i) ans[p].upd(ans[ls][i]);
for(int i=1;i<=ans[rs].top;++i) ans[p].upd(ans[rs][i]);
merge(ans[p],suf[ls],pre[rs]),--ans[p].stk,ans[p][1]={0,0},++ans[p].top,ans[p].build();
}
pre[p].now=suf[p].now=ans[p].now=1,ppre[d]=pre[p].stk+pre[p].top,psuf[d]=suf[p].stk+suf[p].top,pans[d]=ans[p].stk+ans[p].top;
}
data query(int p,int l,int r,int L,int R)
{
if(L==l&&R==r) return {sum[p]+(r-l)*tag,pre[p].cal(),suf[p].cal(),ans[p].cal()};
if(R<=mid) return query(ls,l,mid,L,R);
if(L>=mid) return query(rs,mid,r,L,R);
return query(ls,l,mid,L,mid)+query(rs,mid,r,mid,R);
}
#undef ls
#undef rs
#undef mid
}
struct query{int l,r,id;ll tag;}q[M];
int operator<(const query&a,const query&b){return a.tag<b.tag;}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;++i) a[i]=read();
for(int i=1,l,r;i<=m;++i) (read()==1)? tag+=read():(l=read(),r=read(),++cnt,q[cnt]={l,r,cnt,tag},0ll);
sort(q+1,q+cnt+1),tag=q[1].tag;
for(int i=1;i<=cnt;++i) q[i].tag-=tag;
for(int i=1;i<=n;++i) a[i]+=tag;
segtree::init(),segtree::build(1,0,n,0);
for(int i=1;i<=cnt;++i) tag=q[i].tag,ans[q[i].id]=segtree::query(1,0,n,q[i].l-1,q[i].r).ans;
for(int i=1;i<=cnt;++i) write(ans[i]);
return IO::Flush(),0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Memory Limit Exceeded
input:
300000 600000 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74...
output:
84024307828 1416214378018 1161614211450 567394071867 55678648336 1572518045098 1994743781824 32473532072 468272781165 1923047043804 5238223552422 4680475173970 4582648461140 2163919819875 9861996807548 8736696984876 1974768492984 15710473640275 7537660006317 12685375522657 10538761447043 21118588047...
result:
Test #2:
score: 0
Memory Limit Exceeded
input:
300000 600000 -6000 -12000 -18000 -24000 -30000 -36000 -42000 -48000 -54000 -60000 -66000 -72000 -78000 -84000 -90000 -96000 -102000 -108000 -114000 -120000 -126000 -132000 -138000 -144000 -150000 -156000 -162000 -168000 -174000 -180000 -186000 -192000 -198000 -204000 -210000 -216000 -222000 -228000...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
Test #3:
score: 0
Memory Limit Exceeded
input:
300000 600000 694739332 12000 18000 24000 30000 36000 42000 48000 54000 60000 66000 72000 78000 84000 90000 96000 102000 108000 114000 120000 126000 132000 138000 805133449 150000 156000 162000 168000 174000 180000 186000 192000 198000 204000 210000 216000 222000 372033439 234000 240000 246000 25200...
output:
41604941994237 94971274252954 6338543899673 1459762820309 161224024717481 23155523385223 210709949174517 40274396607189 40938240182271 56061905374465 101707406779068 43959910749717 65421100084429 37886114133244 92323896298094 42560284265070 225802063713016 7254962781020 24024003521065 64740626797068...
result:
Test #4:
score: 0
Memory Limit Exceeded
input:
300000 600000 -370584886 -824446876 -217953152 -213883201 -3695086 -244661761 -31643401 -28513584 -120242422 -164834515 -442171367 -44150185 -373313047 -176037889 -88006209 13397 -137034887 -288429275 -105994131 9344897 -561275521 -739928113 -410398492 -766560640 -234474561 -376898910 -3876489 -7672...
output:
17230992 32777833 28217641 29070607 32933197 28215925 33029101 33030085 29141557 33004045 33004045 33072517 33098197 33098197 23301788 33159993 25721390 33226753 23698608 33445777 33445777 33445777 29453326 28711240 17084471 26742667 33695281 33739365 33739365 33739365 29673517 33844541 33844541 340...
result:
Test #5:
score: 0
Memory Limit Exceeded
input:
300000 600000 211880591 88968133 407526653 911890111 807256887 -176021101 106280356 8936401 282861019 5357877 254177 417572162 -357964741 -381515641 129902155 473664349 -59617567 667379417 776235315 58916209 7886485 223802672 -47045571 804252695 203831125 43372991 28892923 158908981 378392554 -30512...
output:
4942713365399 29306562719793 8900507161207 21290490184270 4596872844788 10238905877827 7925329590354 3777732603397 14745724374577 16055261307200 26178104400752 1676831466655 22846687969518 13938486351276 31186336946271 34930321446248 23953825809791 3028520322375 25899929218051 14237483103680 1048902...
result:
Test #6:
score: 0
Memory Limit Exceeded
input:
300000 600000 478547749 21607029 -89838541 489455731 -26326441 -57796177 11291418 580134112 194452929 323639427 78318073 26812402 543586369 370325145 -15025771 77970751 -57165081 69553200 68373559 103525821 488338363 -114852353 129257857 353303549 120029521 55251574 184069369 116347321 66298177 2323...
output:
2236198842134 35572162546957 495597622193 41494702170655 15685917021182 33264830223358 8589165531202 20475579895477 15162343848182 32419938679249 4199843978146 23391255254912 21514929235993 39268489406569 21361310847580 28797140460551 29879647518758 27385580764559 36950234927291 19703992738484 20129...
result:
Test #7:
score: 0
Memory Limit Exceeded
input:
300000 600000 -167628 147836 342193 -113005 335767 62551 37153 391126 62081 394393 64376 61561 204691 362478 -192721 246628 -34842 558316 210421 492772 63566 -119326 208751 549977 400921 424726 242537 401281 -156335 392551 175009 213401 277477 510111 27205 90706 544489 166673 325195 362819 -1502 497...
output:
26438246588 15640662603 2073561407 42355320361 10702544205 4350848378 27120615273 56771714423 8139504738 56564417213 2471202051 947792265 33220549542 30019144710 11108663857 6067858460 47128684236 25575034151 83248175836 70356187550 55707380244 72859596409 5595976656 64534911553 11692004903 60899247...
result:
Test #8:
score: 0
Memory Limit Exceeded
input:
300000 600000 -52710799 -139860657 -76037377 -383460841 -250485933 -170800931 38569417 -148104385 -366126471 36758571 61991329 -179464171 -336298825 -58594900 22133163 -423137793 -364236327 37740025 -191822446 -86831549 68026423 -113477261 -80044118 -45362365 -154807957 -29767662 -474689591 -1954812...
output:
441139576 339158219 392303592 320580286 321637946 440982472 391918165 354804084 393018180 477837726 339484554 442475092 477871502 442925620 340106149 273672907 340225444 315111566 444715924 394567644 445524436 314926640 341202849 446577280 395199072 446606884 395467263 447066640 289261135 366674918 ...
result:
Test #9:
score: 0
Memory Limit Exceeded
input:
300000 600000 -9317 -17721 83807 -89601 -132992 -21217 -164947 -15601 -168899 190720 -33799 -114351 -91457 -194029 132053 -109571 -65991 -107846 -77121 -90550 -162626 -66021 -52064 -69881 55395 -187207 -41697 -152345 76528 -97151 -172721 100673 -190401 -29409 -62929 -112268 -92705 -165993 -61056 -37...
output:
1197119 1197119 1197139 1197139 1197139 1197139 1197179 1197179 1197179 1197179 1197179 1197179 1197179 1197199 1197219 1197219 1197219 1197259 1197279 1197279 1197279 1197279 1197319 1197319 1197319 1197319 1197319 1197379 1197419 1197419 1197419 1197419 1197459 1197459 1197459 1197459 1197459 1197...
result:
Test #10:
score: 0
Memory Limit Exceeded
input:
300000 600000 -9317 -17721 83807 -89601 -132992 -21217 -164947 -15601 -168899 190720 -33799 -114351 -91457 -194029 132053 -109571 -65991 -107846 -77121 -90550 -162626 -66021 -52064 -69881 55395 -187207 -41697 -152345 76528 -97151 -172721 100673 -190401 -29409 -62929 -112268 -92705 -165993 -61056 -37...
output:
838372 1197119 1113323 1197139 838378 764762 1197179 945208 690830 824699 1197179 1197179 1113349 897113 945226 897120 897120 1197259 945253 702721 1197279 1197279 838432 945271 945271 1113440 1197319 1197379 1197419 1197419 1113505 1197419 1197459 769584 673847 1197459 1197459 745374 1197459 824853...
result:
Test #11:
score: 0
Memory Limit Exceeded
input:
300000 600000 -350031 -418621 -379153 -349541 -204935 -413677 -290785 -73634 -339579 -86194 -237211 -393502 -477091 -479966 -452057 -384481 -843294 -221408 -132345 -109333 -149097 -483897 -29033 -220275 -50099 -39225 -148729 -397731 -222829 -436818 -233585 -433945 -335641 -44285 -107328 -338151 -534...
output:
1 0 17 17 21 0 23 23 23 23 25 31 31 31 31 31 37 37 45 45 49 51 53 53 53 57 59 63 69 73 73 67 87 87 87 89 91 93 93 99 103 103 115 129 129 129 129 131 131 131 141 141 141 149 151 151 151 151 151 151 157 157 161 167 173 173 175 181 181 181 191 191 195 201 201 201 209 213 213 225 237 245 245 247 247 247...
result:
Test #12:
score: 0
Memory Limit Exceeded
input:
300000 600000 -696987827 1791548840 1540245114 -744556712 281332436 -396365348 -660700017 -926408705 66098449 1448486061 -1945919603 1080362360 732219815 -519568302 1228792006 364734706 -1151351486 -1056003603 -1852483513 -1758573146 762059937 -333873273 -1645890512 1388909837 -267565502 1028489524 ...
output:
34875202474 34875202474 47719620941 34260902731 41521681581 61204182825 46104305835 32659298643 30887043395 31638188654 30887043395 23362189245 34355555753 27610920431 24195330313 18310484872 17339841108 14530808341 10357417984 20767438592 16403611599 11290249515 16403611599 14206158426 10354664320 ...