Soul_direction @ 2024-07-06 11:04:58
本地能过,开 freopen
就炸,快读快写没问题,就是自闭(厌
#pragma gcc optimize(2)
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
#define maxn 1000010
#define inf 2147483647
using namespace std;
int n,q,l,r;
int tree[4*maxn],a[maxn];
char op;
void buildtree(int lowbit,int l,int r){
if(l==r)tree[lowbit]=a[l];
int mid=(l+r)>>1;
buildtree(lowbit*2,l,mid);
buildtree(lowbit*2+1,mid+1,r);
tree[lowbit]=max(tree[lowbit*2],tree[lowbit*2+1]);
}
int find(int lowbit,int l,int r,int b,int e){
if(b<=l&&r<=e)return tree[lowbit];
int mid=(l+r)>>1,ans=-1e18;
if(b<=mid)ans=max(ans,find(lowbit*2,l,mid,b,e));
if(e>mid)ans=max(ans,find(lowbit*2+1,mid+1,r,b,e));
return ans;
}
void turn(int lowbit,int l,int r,int b,int e,int tmp){
if(l==r)tree[lowbit]=tmp;
int mid=(l+r)>>1;
if(b<=mid)turn(lowbit*2,l,mid,b,e,tmp);
if(e>mid)turn(lowbit*2+1,mid+1,r,b,e,tmp);
tree[lowbit]=max(tree[lowbit*2],tree[lowbit*2+1]);
}
void add(int lowbit,int l,int r,int b,int e,int tmp){
if(l==r)tree[lowbit]+=tmp;
int mid=(l+r)>>1;
if(b<=mid)add(lowbit*2,l,mid,b,e,tmp);
if(e>mid)add(lowbit*2+1,mid+1,r,b,e,tmp);
tree[lowbit]=max(tree[lowbit*2],tree[lowbit*2+1]);
}
inline int read(){
int x=0,f; char ch=0;
while(!isdigit(ch)) f=(ch=='-'?-1:1),ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
inline void print(int x){
if(x<0) x=-x,putchar('-');
if(x>9) print(x/10);
putchar(x%10+48);
}
inline void write(int x){print(x);putchar('\n');}
signed main(){
n=read(),q=read();
for(int i=1;i<=n;i++)a[i]=read();
buildtree(1,1,n);
while(q--){
cin>>op;
int s=read(),f=read();
int x;
if(op=='1'){
x=read();
turn(1,1,n,s,f,x);
}else if(op=='2'){
x=read();
add(1,1,n,s,f,x);
}else{
write(find(1,1,n,s,f));
}
}
return 0;
}
by hehejushi @ 2024-07-10 09:27:55
@Soul_direction
return?
by Soul_direction @ 2024-07-13 13:14:05
@hehejushi
?