#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvvl vector #define vvl vector> #define VV(a, b, c, d) vector>(a, vector(b, c)) #define VVV(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c dat; segtree(ll N, ll num){ INIT = num; while(M0) k = (k-1)/2, dat[k] = dat[k*2+1] + dat[k*2+2]; } ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){ if(r==-1) r = M; if(b==-1) b = M; if(r<=a || b<=l) return INIT; if(a<=l && r<=b) return dat[k]; ll A = query(a, b, k*2+1, l, (l+r)/2); ll B = query(a, b, k*2+2, (l+r)/2, r); return A + B; } }; typedef tuple tp; //x, l, r, idx int main(int argc, char const *argv[]) { ll n, q;std::cin >> n >> q; segtree seg(n+1, 0), cnt(n+1, 0); multiset st; for(int i=0;i(*itr); ll b = get<1>(*itr); ll c = get<2>(*itr); ll d = get<3>(*itr); if(b==-1) seg.update(a, c), cnt.update(1, c); else{ ll S = seg.query(b-1, c); ll num = cnt.query(b-1, c); //std::cout << S << " " << num << " " << d << '\n'; ans[d] = S - num * a; } } for(int i=0;i