#include using namespace std; int tree[10000001],upd[10000001],st,n,ans; void find1 (int ind, int beg, int end1, int l, int r) { ans+=(end1-beg+1)*upd[ind]; // ans += upd[ind]; if ((l<=beg)&&(end1<=r)) { ans+=tree[ind]; return ; } if (l<=(beg+end1)/2) find1(2*ind+1,beg,(beg+end1)/2,l,r); if (r>(beg+end1)/2) find1(2*ind+2,(beg+end1)/2+1,end1,l,r); } int update (int ind, int beg, int end1, int l, int r, int val) { if ((l<=beg)&&(end1<=r)) { ans = 0; find1(0,0,st,beg,end1); cerr << "x: " << val << endl; cerr << "b, e: " << beg << " " << end1 << endl; cerr << "l, r: " << l << " " << r << endl; cerr << "s: " << ans << endl; cerr << "f: " << (end1-beg)*val - ans - ans << endl; cerr << endl; upd[ind] += (end1-beg)*val - ans - ans; return (end1-beg)*val - ans - ans; } int change=0; if (l<=(beg+end1)/2) change+=update(2*ind+1,beg,(beg+end1)/2,l,r,val); if (r>(beg+end1)/2) change+=update(2*ind+2,(beg+end1)/2+1,end1,l,r,val); tree[ind]+=change; return 0; } int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("accounting.in", "r", stdin); freopen("accounting.out", "w", stdout); int i,q,l,r,val; cin >> n >> q; st=1; for (;;) { if (st>=n) break; st*=2; } st--; for (i=0; i> tree[st+i] ; for (i=st-1; i>=0; i--) tree[i]=tree[2*i+1]+tree[2*i+2]; for (i=0; i> type >> l >> r ; l--; r--; if (type=='-') { cin >> val ; update(0,0,st,l,r,val); } else { ans=0; find1(0,0,st,l,r); cout << ans << '\n' ; } } return 0; } /** 5 7 57 18 40 89 7 - 2 3 94 ? 1 5 ? 3 5 - 2 4 41 ? 2 4 ? 1 5 ? 3 4 */