#include #include using namespace std; const int maxn=(1<<17); struct seg_tree { long long sum; int lazy; bool lazy_flag; seg_tree(){sum=lazy=lazy_flag=0;} seg_tree(int _num) { sum=_num; lazy=0; lazy_flag=false; } }; seg_tree t[maxn*2]; int n,q,a[maxn]; void make_tree(int root,int l,int r) { if(l==r)t[root].sum=a[l]; else { int mid=(l+r)/2; make_tree(root*2,l,mid); make_tree(root*2+1,mid+1,r); t[root].sum=t[root*2].sum+t[root*2+1].sum; } } void push_lazy(int root,int l,int r) { if(t[root].lazy_flag==0)return; t[root].lazy_flag=false; t[root].sum=(t[root].lazy*(r-l+1)-t[root].sum); if(l<=r) { t[root*2].lazy+=t[root].lazy; t[root*2].lazy_flag=true; t[root*2+1].lazy+=t[root].lazy; t[root*2+1].lazy_flag=true; } t[root].lazy=0; } void update_lazy(int root,int l,int r,int ql,int qr,int lazy) { if(l==ql&&r==qr) { t[root].lazy+=lazy; t[root].lazy_flag=true; push_lazy(root,l,r); return; } push_lazy(root,l,r); int mid=(l+r)/2; if(qr<=mid) { push_lazy(root*2+1,mid+1,r); update_lazy(root*2,l,mid,ql,qr,lazy); } else if(ql>mid) { push_lazy(root*2,l,mid); update_lazy(root*2+1,mid+1,r,ql,qr,lazy); } else { update_lazy(root*2,l,mid,ql,mid,lazy); update_lazy(root*2+1,mid+1,r,mid+1,qr,lazy); } push_lazy(root,l,r); push_lazy(root*2,l,mid); push_lazy(root*2+1,mid+1,r); t[root].sum=t[root*2].sum+t[root*2+1].sum; } long long query(int root,int l,int r,int ql,int qr) { push_lazy(root,l,r); if(l==ql&&r==qr) return t[root].sum; int mid=(l+r)/2; if(qr<=mid) { push_lazy(root*2+1,mid+1,r); return query(root*2,l,mid,ql,qr); } else if(ql>mid) { push_lazy(root*2,l,mid); return query(root*2+1,mid+1,r,ql,qr); } else return query(root*2,l,mid,ql,mid)+ query(root*2+1,mid+1,r,mid+1,qr); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ifstream fin; ofstream fout; fin.open("accounting.in"); fout.open("accounting.out"); fin>>n>>q; for(int i=1;i<=n;++i) fin>>a[i]; make_tree(1,1,n); char c;int l,r,lazy; for(int q1=0;q1>c>>l>>r; if(c=='-') { fin>>lazy; update_lazy(1,1,n,l,r,lazy); } if(c=='?') fout<