50分,后面5个WA

P1253 扶苏的问题

@[GXYZY](/user/508177) `long long`
by WsW_ @ 2023-11-15 22:44:16


似乎不是long long的问题?
by cat_lover1 @ 2023-11-15 22:55:31


确实不是long long的问题
by GXYZY @ 2023-11-15 22:58:36


@[cz_awa](/user/246331) 你说的对
by GXYZY @ 2023-11-15 22:59:06


@[GXYZY](/user/508177) 我现在一通瞎改,又得回40分了,其余都是TLE
by cat_lover1 @ 2023-11-15 23:02:19


@[GXYZY](/user/508177) 两个问题 ![](https://cdn.luogu.com.cn/upload/image_hosting/zx0wdl5d.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/tuix0se7.png)
by Transparent @ 2023-11-15 23:29:30


@[GXYZY](/user/508177) 改出来了,的确有long long的问题。注释的部分即修改处 ```cpp #include<bits/stdc++.h> // #pragma GCC optimize(2) // #define int long long #define ll long long// using namespace std; const ll inf=1e18;// int read(){ int x=0,f=1; char c=getchar(); while(c>'9'||c<'0'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar(); } return x*f; } void write(ll x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); return ; } int n,q,/*a[1000006],*/op,x,y,z; struct segtree{ int lc,rc; ll mmax,addlazy,changelazy; bool ifchange; }node[5000006]; void pushup(int st){ node[st].mmax=max(node[st*2].mmax,node[st*2+1].mmax); return ; } void build(int st,int l,int r){ node[st].lc=l; node[st].rc=r; if(l==r){ node[st].mmax=read();// return ; } int md=(l+r)/2; build(st*2,l,md); build(st*2+1,md+1,r); pushup(st); return ; } void pushdown(int st){ if(node[st].ifchange==1){ node[st*2].changelazy=node[st].changelazy; node[st*2].addlazy=0; node[st*2].mmax=node[st].changelazy; node[st*2+1].changelazy=node[st].changelazy; node[st*2+1].addlazy=0; node[st*2+1].mmax=node[st].changelazy; node[st*2].ifchange=node[st*2+1].ifchange=1;// //node[st].changelazy=0; node[st].ifchange=0; } else if(node[st].addlazy!=0){ if(node[st*2].ifchange==1){ node[st*2].changelazy+=node[st].addlazy; } else{ node[st*2].addlazy+=node[st].addlazy; } node[st*2].mmax+=node[st].addlazy; if(node[st*2+1].ifchange==1){ node[st*2+1].changelazy+=node[st].addlazy; } else{ node[st*2+1].addlazy+=node[st].addlazy; } node[st*2+1].mmax+=node[st].addlazy; node[st].addlazy=0; } return ; } void changeinterval(int st,int l,int r,int data){ if(node[st].lc>r||node[st].rc<l) return ; if(node[st].lc>=l&&node[st].rc<=r){ node[st].mmax=data; node[st].changelazy=data; node[st].addlazy=0; node[st].ifchange=1; return ; } pushdown(st); changeinterval(st*2,l,r,data); changeinterval(st*2+1,l,r,data); pushup(st); return ; } void addinterval(int st,int l,int r,int data){ if(node[st].lc>r||node[st].rc<l) return ; if(node[st].lc>=l&&node[st].rc<=r){ node[st].mmax+=data; if(node[st].ifchange==1){ node[st].changelazy+=data; } else{ node[st].addlazy+=data; } return ; } pushdown(st); addinterval(st*2,l,r,data); addinterval(st*2+1,l,r,data); pushup(st); return ; } ll getmax(int st,int l,int r){ if(node[st].lc>r||node[st].rc<l) return -inf; if(node[st].lc>=l&&node[st].rc<=r){ return node[st].mmax; } pushdown(st); return max(getmax(st*2,l,r),getmax(st*2+1,l,r)); } int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); n=read(); q=read(); //for(int i=1;i<=n;i++){ //a[i]=read(); //} build(1,1,n); while(q--){ op=read();x=read();y=read(); if(op==1)changeinterval(1,x,y,read());//注:函数中只能有最多1个read,出现多了就wa了 else if(op==2)addinterval(1,x,y,read()); else{ write(getmax(1,x,y)); putchar('\n'); } } return 0; } ```
by cat_lover1 @ 2023-11-16 10:10:24


@[Transparent](/user/180576) @[cz_awa](/user/246331) 已经解决了,太感谢了
by GXYZY @ 2023-11-16 22:41:28


|