shalu @ 2023-08-08 15:58:33
不知到怎么的就RE了5个点QAQ,贴代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=1e6+5;
int n,q,tmp[MAXN],f[MAXN<<2],v1[MAXN<<2],v2[MAXN<<2];
void update(int k){
f[k]=max(f[k+k],f[k+k+1]);
return ;
}
void pushdown(int k,int l,int r){
int mid=(l+r)>>1;
if(v1[k]!=INF){
v1[k+k]=v1[k+k+1]=v1[k];
v2[k+k]=v2[k+k+1]=0;
f[k+k]=f[k+k+1]=v1[k];
v1[k]=INF;
}
if(v2[k]){
v2[k+k]+=v2[k];
v2[k+k+1]+=v2[k];
f[k+k]+=v2[k];
f[k+k+1]+=v2[k];
v2[k]=0;
}
return ;
}
inline void buildtree(int k,int l,int r){
v1[k]=INF,v2[k]=0;
if(l==r){
f[k]=tmp[l];
return ;
}
int mid=(l+r)>>1;
buildtree(k+k,l,mid);
buildtree(k+k+1,mid+1,r);
update(k);
}
inline void insert(int k,int l,int r,int x,int y,int z){
if(l==x&&r==y){
v1[k]=z;
f[k]=z;
v2[k]=0;
return ;
}
pushdown(k,l,r);
int mid=(l+r)>>1;
if(y<=mid){
insert(k+k,l,r,x,y,z);
}
else{
if(x>mid){
insert(k+k+1,mid+1,r,x,y,z);
}
else{
insert(k+k,l,mid,x,mid,z),insert(k+k+1,mid+1,r,mid+1,y,z);
}
}
update(k);
}
inline void add(int k,int l,int r,int x,int y,int z){
if(l==x&&r==y){
v2[k]+=z;
f[k]+=z;
return ;
}
pushdown(k,l,r);
int mid=(l+r)>>1;
if(y<=mid){
add(k+k,l,mid,x,y,z);
}
else{
if(x>mid){
add(k+k+1,mid+1,r,x,y,z);
}
else{
add(k+k,l,mid,x,mid,z),add(k+k+1,mid+1,r,mid+1,y,z);
}
}
update(k);
}
int calc(int k,int l,int r,int x,int y){
if(l==x&&r==y){
return f[k];
}
pushdown(k,l,r);
int mid=(l+r)>>1;
if(y<=mid){
return calc(k+k,l,mid,x,y);
}
else{
if(x>mid){
return calc(k+k+1,mid+1,r,x,y);
}
else{
return max(calc(k+k,l,mid,x,mid),calc(k+k+1,mid+1,r,mid+1,y));
}
}
}
signed main(){
std::ios::sync_with_stdio(false);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>tmp[i];
}
buildtree(1,1,n);
for(int i=1;i<=q;i++){
int op,x,y,z;
cin>>op;
if(op==1){
cin>>x>>y>>z;
insert(1,1,n,x,y,z);
}
else if(op==2){
cin>>x>>y>>z;
add(1,1,n,x,y,z);
}
else{
cin>>x>>y;
cout<<calc(1,1,n,x,y)<<endl;
}
}
return 0;
}
by Trump_ @ 2023-08-08 16:10:35
@shalu
inline void insert(int k,int l,int r,int x,int y,int z){
if(y<=mid){
insert(k+k,l,mid,x,y,z);
}
```cpp
by Trump_ @ 2023-08-08 16:10:59
但是,你好,又见面了QAQ
by shalu @ 2023-08-08 16:20:48
@Trump_啊这
by shalu @ 2023-08-08 16:22:03
@Trump_ 感谢大佬指点,%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%