比赛 |
2025.5.5 |
评测结果 |
WATTTTTTTT |
题目名称 |
愈加善良的希望 |
最终得分 |
10 |
用户昵称 |
dream |
运行时间 |
16.047 s |
代码语言 |
C++ |
内存使用 |
5.92 MiB |
提交时间 |
2025-05-05 10:31:57 |
显示代码纯文本
#include<bits/stdc++.h>
#define ls p*2
#define rs p*2+1
using namespace std;
typedef long long ll;
const int N=50005;
int n,q;
struct node{
int l,r;
ll sum,add;
}tr[N*4];
ll a[N];
void pushup(int p){
tr[p].sum=tr[ls].sum+tr[rs].sum;
}
void build(int p,int l,int r){
tr[p]={l,r,0,0};
if(l==r){
tr[p].sum=a[l];
return;
}
int mid=(l+r)/2;
build(ls,l,mid);
build(rs,mid+1,r);
pushup(p);
}
void pushdown(int p){
tr[ls].add+=tr[p].add;
tr[rs].add+=tr[p].add;
tr[ls].sum+=tr[p].add*(tr[ls].r-tr[ls].l+1);
tr[rs].sum+=tr[p].add*(tr[rs].r-tr[rs].l+1);
tr[p].add=0;
}
void update(int p,int l,int r,ll v){
if(l<=tr[p].l&&tr[p].r<=r){
tr[p].sum+=v*(tr[p].r-tr[p].l+1);
tr[p].add+=v;
return;
}
pushdown(p);
int mid=(tr[p].l+tr[p].r)/2;
if(l<=mid){
update(ls,l,r,v);
}
if(r>mid){
update(rs,l,r,v);
}
pushup(p);
}
ll query(int p,int l,int r){
if(l<=tr[p].l&&tr[p].r<=r){
return tr[p].sum;
}
pushdown(p);
int mid=(tr[p].l+tr[p].r)/2;
ll res=0;
if(l<=mid){
res+=query(ls,l,r);
}
if(r>mid){
res+=query(rs,l,r);
}
return res;
}
int main(){
freopen("hod.in","r",stdin);
freopen("hod.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build(1,1,n);
cin>>q;
for(int i=1;i<=q;i++){
int op,l,r,v;
cin>>op>>l>>r;
if(op==0){
cin>>v;
update(1,l,r,v);
}
else{
ll mx=-2147483648;
for(int j=l;j<=r;j++){
mx=max(mx,query(1,1,j));
}
cout<<mx<<"\n";
}
}
return 0;
}