那位大佬能能救救蒟蒻
P1253 扶苏的问题只过了第一点和样例,已经调了一个半小
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
const int N=1e6+50,ma=INT_MAX;
ll tree[4*N],a[N],q,n,tag1[4*N],tag2[4*N],ans;
int ls(int p){
return p<<1;
}
int rs(int p){
return (p<<1)|1;
}
void push_up(int p){
tree[p]=max(tree[ls(p)],tree[rs(p)]);
return ;
}
void build(int p,int pl,int pr){
tag1[p]=ma;
tag2[p]=0;
if(pl==pr){
tree[p]=a[pl];
return ;
}
int mid=(pl+pr)>>1;
build(ls(p),pl,mid);
build(rs(p),mid+1,pr);
push_up(p);
return ;
}
void addtag(int op,int p,ll d){
if(op==1&&d!=ma){
tag1[p]=d;
tag2[p]=0;
tree[p]=d;
}
if(op==2){
tag2[p]+=d;
tree[p]+=d;
}
return ;
}
void push_down(int p){
if(tag1[p]!=ma){
addtag(1,ls(p),tag1[p]);
addtag(1,rs(p),tag1[p]);
tag1[p]=ma;
}
if(tag2[p]){
addtag(2,ls(p),tag2[p]);
addtag(2,ls(p),tag2[p]);
tag2[p]=0;
}
return ;
}
void update(int op,int L,int R,int pl,int pr,int p,ll d){
if(L<=pl&&R>=pr){
addtag(op,p,d);
return ;
}
push_down(p);
int mid=(pl+pr)>>1;
if(L<=mid){
update(op,L,R,pl,mid,ls(p),d);
}
if(R>mid){
update(op,L,R,mid+1,pr,rs(p),d);
}
push_up(p);
return ;
}
ll query(int L,int R,int pl,int pr,int p){
if(L<=pl&&R>=pr){
return tree[p];
}
push_down(p);
int mid=(pl+pr)>>1;
ll sum=INT_MIN;
if(L<=mid){
sum=max(query(L,R,pl,mid,ls(p)),sum);
}
if(R>mid){
sum=max(query(L,R,mid+1,pr,rs(p)),sum);
}
return sum;
}
int main()
{
n=read();
q=read();
for(int i=1;i<=n;i++){
a[i]=read();
}
build(1,1,n);
for(int i=1;i<=q;i++){
int op,l,r;
ll x;
op=read();
l=read();
r=read();
if(op==1){
x=read();
update(op,l,r,1,n,1,x);
}
else if(op==2){
x=read();
update(op,l,r,1,n,1,x);
}
else if(op==3){
ans=query(l,r,1,n,1);
printf("%lld\n",ans);
}
}
return 0;
}
了