/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
const int maxn = 1e5 + 10;
int n, q;
ll a[maxn], group[maxn], num[maxn];
bool cut[maxn];
ll query(int l, int r)
{
    for (int i = 0; i <= n; i ++)
        num[i] = 0;
    group[1] = 0;
    num[group[1]] = max(num[group[1]], a[1]);
    for (int i = 2; i <= n; i ++)
    {
        group[i] = group[i - 1];
        if (cut[i - 1])
            group[i] ++;

    }
    for (int i = l; i <= r; i ++)
    num[group[i]] = max(num[group[i]], a[i]);

    ll ans = 0;
    if (group[l] % 2 == 1)
        ans = ans + num[group[l]];

    for (int i = l + 1; i <= r; i ++)
    {
        if (group[i] != group[i - 1] && group[i] % 2 == 1)
            ans = ans + num[group[i]];
    }

    return ans;
}
void solve()
{
    cin >> n >> q;
    int type, p, c, l, r;
    ll s;
    for (int i = 1; i <= q; i ++)
    {
        cin >> type;
        if (type == 1)
        {
            cin >> p;
            cut[p] = 1;
        }
        else
        if (type == 2)
        {
            cin >> p;
            cut[p] = 0;
        }
        else
        if (type == 3)
        {
            cin >> c >> s;
            a[c] += s;
        }
        else
        if (type == 4)
        {
            cin >> l >> r;

            cout << query(l, r) << endl;
            /**for (int i = 1; i <= n; i ++)
                cout << a[i] << " ";
            cout << endl;
            for (int i = 1; i <= n; i ++)
                cout << group[i] << " ";
            cout << endl;*/
        }
    }
}

int main()
{
    speed();
    solve();
    return 0;
}

