#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define REP(i,n) for(long long i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
ll INF = 1LL << 60;
const ll sqrtN = 512; //* 512*512=262144 > 10^5

//* reference: https://kujira16.hateblo.jp/entry/2016/12/15/000000
//* Range Sum Query (RSQ) implemented using sqrt decomposition
struct RSQ{ 
    ll N, K; //* N length of data, K number of buckets
    vll data;
    vll bucketSum;
    //* allocate memory with zeros
    void init(ll n){
        N = n;
        K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN)
        data.assign(K * sqrtN, 0);
        bucketSum.assign(K, 0);
    }
    //* constructor
    RSQ(ll n){ init(n);}
    //* constructor with init vector data
    RSQ(ll n, vll &a){
        init(n);
        REP(i, n){
            data[i] = a[i];
        }
        REP(k, K){
            ll sum = 0;
            for(ll j = k * sqrtN; j < (k + 1)* sqrtN; j++){
                sum += data[j];
            }
            bucketSum[k] = sum;
        }
    }
    //* update (add(i, x) -> a[i]+= x)
    void add(ll i, ll x){
        ll k = i / sqrtN; //* corresponding bucket
        data[i] += x;
        ll sum = 0;
        for(ll j = k * sqrtN ; j < (k + 1)*sqrtN; j ++){
            sum += data[j];
        }
        bucketSum[k] = sum;
    }
    //* getSum(s, t)-> return a[s]+a[s+1]+...+a[t-1]
    //* [x, y)
    ll getSum(ll x, ll y){
        ll sum = 0;
        REP(k, K){
            ll l= k * sqrtN, r = (k+1) * sqrtN; //* bucket [l, r)
            if(r <= x || y <= l) //* no intersection
                continue;
            if(x <= l && r <= y) {//* [l, r) in [x, y)
                sum += bucketSum[k]; //* use bucket data
            }
            else{ //* has intersection on boundary
                for(ll i = max(l, x); i < min(r, y); i++){
                    sum += data[i];
                }
            }
        }
        return sum;
    }
};
//* reference: https://kujira16.hateblo.jp/entry/2016/12/15/000000
//* Range Minimum Query (RMQ) implemented using sqrt decomposition
struct RMQ{
    ll N, K;
    vll data;
    vll bucketMin;
    //* allocate memory with zeros
    void init(ll n){
        N = n;
        K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN)
        data.assign(K * sqrtN, INF);
        bucketMin.assign(K, INF);
    }
    //* constructor
    RMQ(ll n){ init(n);}
    //* constructor with init vector data
    RMQ(ll n, vll &a){
        init(n);
        REP(i, n){
            data[i] = a[i];
        }
        REP(k, K){
            ll tmp = INF;
            for(ll j = k * sqrtN; j < (k + 1)* sqrtN; j++){
                tmp =min(tmp, data[j]);
            }
            bucketMin[k] = tmp;
        }
    }
    //* update a[i] = x
    void update(ll i, ll x){
        ll k = i / sqrtN; //* corresponding bucket
        if(x <= data[i]){ //* fast update
            data[i] = x;
            bucketMin[k] = min(x, bucketMin[k]);
            return;
        }
        data[i] = x;
        ll tmp = x;
        for(ll j = k * sqrtN; j < (k+1)*sqrtN; j++){
            tmp = min(tmp, data[j]);
        }

        bucketMin[k] = tmp;
    }
    //* find(s, t)-> return min(a[s], a[s+1], ..., a[t-1])
    //* [x, y)
    ll find(ll x, ll y){
        ll tmp = INF;
        REP(k, K){
            ll l= k * sqrtN, r = (k+1) * sqrtN; //* bucket [l, r)
            if(r <= x || y <= l) //* no intersection
                continue;
            if(x <= l && r <= y) {//* [l, r) in [x, y)
                tmp = min(tmp, bucketMin[k]); //* use bucket data
            }
            else{ //* has intersection on boundary
                for(ll i = max(l, x); i < min(r, y); i++){
                    tmp = min(tmp, data[i]);
                }
            }
        }
        return tmp;
    }
};
//* reference: https://kujira16.hateblo.jp/entry/2016/12/15/000000
//* Range Add Query (RAQ) implemented using sqrt decomposition
struct RAQ{
    ll N, K;
    vll data;
    vll bucketAdd;
    //* init using 0 data
    void init(ll n){ 
        N = n;
        K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN)
        data.assign(K * sqrtN, 0);
        bucketAdd.assign(K, 0);
    }
    //* constructor
    RAQ(ll n){ init (n); }
    RAQ(ll n, vll const &a){
        init(n);
        REP(i, n){
            data[i] = a[i];
        }
        //* zero initialization is enough
    }
    //* update [s, t) with addition x
    void add(ll s, ll t, ll x){
        REP(k, K){
            ll l= k * sqrtN, r = (k + 1) * sqrtN; //* bucket [l, r)
            if(r <= s || t <= l) //* no intersection
                continue;
            if(s <= l && r <= t) {//* [l, r) in [x, y)
                bucketAdd[k] += x; //* update bucket data
            }
            else{ //* has intersection on boundary
                for(ll i = max(l, s); i < min(r, t); i++){
                    data[i] += x;
                }
            }
        }
    }
    //* get i-th data
    ll get(ll i){
        ll k = i / sqrtN;
        return data[i] + bucketAdd[k];
    }

};
//* reference: https://kujira16.hateblo.jp/entry/2016/12/15/000000
//* Range Update Query (RUQ) implemented using sqrt decomposition
struct RUQ{
    ll N, K;
    vll data;
    vll lazyUpdate;
    vector<bool> lazyFlag;
    //* allocate memory
    void init(ll n){
        N = n;
        K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN)
        data.assign(K * sqrtN, 0);
        lazyUpdate.assign(K, 0);
        lazyFlag.assign(K, false);
    }
    //* constructor
    RUQ(ll n){ init(n);}
    RUQ(ll n, vll &a){
        init(n);
        REP(i, n){
            data[i] = a[i];
        }
    }
    //* update data using lazyUpdate data
    void eval(ll k) {
        if (lazyFlag[k]) {
            //* lazyFlag of the bucket set to false
            lazyFlag[k] = false;
            //* update data in the bucket
            for (ll i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
                data[i] = lazyUpdate[k];
            }
        }
    }
    //* [s, t) update with x
    void update(ll s, ll t, ll x){
        REP(k, K){
            ll l= k * sqrtN, r = (k+1) * sqrtN; //* bucket [l, r)
            if(r <= s || t <= l) //* no intersection
                continue;
            if(s <= l && r <= t) {//* [l, r) in [x, y)
                lazyUpdate[k] = x;
                lazyFlag[k] = true;
            }
            else{
                eval(k); //* for O(1) buckets we just update the data
                for(ll i = max(l, s); i < min(r, t); i++){
                    data[i] = x;
                }
            }
        }
    }
    //* find i-th data
    ll find(ll i){
        ll k = i / sqrtN; //* bucket index
        eval(k);
        return data[i];
    }
};
//* reference: https://kujira16.hateblo.jp/entry/2016/12/15/000000
//* Range Sum Query (RSQ)+ Range Add Update (RAQ) implemented using sqrt decomposition
struct RSQRAQ{
    ll N, K;
    vll data;
    vll bucketSum;
    vll bucketAdd;
    //* init using 0 data
    void init(ll n){
        N = n;
        K = (n + sqrtN - 1) / sqrtN; //* number of buckets = ceil(n/sqrtN)
        data.assign(K * sqrtN, 0);
        bucketSum.assign(K, 0);
        bucketAdd.assign(K, 0);
    }
    //* constructor
    RSQRAQ(ll n){ init(n);}
    RSQRAQ(ll n, vll &a){
        init(n);
        REP(i, n){
            data[i] = a[i];
        }
        REP(k, K){
            ll sum = 0;
            for(ll j = k * sqrtN; j < (k + 1)* sqrtN; j++){
                sum += data[j];
            }
            bucketSum[k] = sum;
        }
        //* no need to change bucketAdd
    }
    //* range addition update [s, t)
    void add(ll s, ll t, ll x){
        REP(k, K){
            ll l= k * sqrtN, r = (k+1) * sqrtN; //* bucket [l, r)
            if(r <= s || t <= l) //* no intersection
                continue;
            if(s <= l && r <= t) {//* [l, r) in [x, y)
                bucketAdd[k] += x; //* update bucketAdd to store x info
            }
            else{ //* has intersection on boundary
                for(ll i = max(l, s); i < min(r, t); i++){
                    data[i] += x;
                    bucketSum[k] += x;
                }
            }
        }
    }
    //* range sum query [s, t)
    ll getSum(ll s, ll t){
        ll sum = 0;
        REP(k, K){
            ll l= k * sqrtN, r = (k+1) * sqrtN; //* bucket [l, r)
            if(r <= s || t <= l) //* no intersection
                continue;
            if(s <= l && r <= t) {//* [l, r) in [x, y)
                sum += bucketSum[k];
                sum += sqrtN * bucketAdd[k];
            }
            else{ //* has intersection on boundary
                for(ll i = max(l, s); i < min(r, t); i++){
                    //* at any time, value of i-th data = data[i]+bucketAdd[k]
                    sum += data[i];
                    sum += bucketAdd[k];
                }
            }
        }
        return sum;
    }
};

void solveRSQ(){
    ll N, Q;
    cin >> N >> Q;
    RSQ st(N);
    REP(q, Q){
        ll com;
        cin >> com;
        if(com){
            ll x, y;
            cin >> x >> y;
            cout << st.getSum(x-1, y)<<endl;
        }
        else{
            ll i, x;
            cin >> i >> x;
            st.add(i-1, x);
        }
    }

}

void solveRMQ(){
    ll n, q;
    cin >> n >> q;
    vll a(n, (1LL<<31)-1);
    RMQ st(n, a);
    REP(_, q){
        ll com;
        cin >> com;
        if(com){//* 
            ll x, y;
            cin >> x >> y;
            cout << st.find(x, y+1) << endl;
        }
        else{ //* update
            ll i, y;
            cin >> i >> y;
            st.update(i, y);
        }
    }
}

void solveRAQ(){
    ll N, Q;
    cin >> N >> Q;
    RAQ st(N);
    REP(q, Q){
        ll com;
        cin >> com;
        if(com){
            ll i;
            cin >> i;
            cout << st.get(i-1)<<endl;
        }
        else{
            ll s, t, x;
            cin >> s >> t >> x;
            st.add(s-1, t, x);
        }
    }
}

void solveRUQ(){
    ll N, Q;
    cin >> N >> Q;
    vll a(N, ((1LL<<31)-1));
    RUQ st(N, a);
    REP(q, Q){
        ll com;
        cin >> com;
        if(com == 0){ //* update(s, t, x)
            ll s, t, x;
            cin >> s >> t >> x;
            t++;
            st.update(s, t, x);
        }
        else{ //* com == 1
            ll i;
            cin >> i; 
            cout << st.find(i)<<endl;
        }
    }
}

void solveRSQRAQ(){
    //* 1-based input
    ll N, Q;
    cin >> N >> Q;
    vll a(N, 0);
    RSQRAQ st(N, a);
    REP(q, Q){
        ll com;
        cin >> com;
        if(com == 0){ //* range addition update
            ll s, t, x;
            cin >> s >> t >> x;
            s --;
            st.add(s, t, x);
        }
        else{ //* com == 1: range sum query
            ll s, t;
            cin >> s >> t;
            s--;
            cout << st.getSum(s, t) << endl;
        }
    }
}

int main(){
    //* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B
    // solveRSQ();
    //* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
    // solveRMQ();
    //* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E&lang=ja
    // solveRAQ();
    //* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_D
    // solveRUQ();
    //* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G&lang=ja
    solveRSQRAQ();

    return 0;
}


Measured memory_bytes: 4380