#include <iostream>
#define endl '\n'
using namespace std;

const int MAXN = 100000;

int d[MAXN + 5];
long long points[MAXN + 5];

int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, q;
    cin >> n >> q;

    while (q--)
    {
        int type;
        cin >> type;

        if (type == 1 or type == 2)
        {
            int p;
            cin >> p;
            d[p] ^= 1;
        }
        else if (type == 3)
        {
            int c, a;
            cin >> c >> a;
            points[c] += a;
        }
        else
        {
            int l, r;
            cin >> l >> r;

            int cnt = 0;
            for (int i = 1; i < l; ++ i)
            {
                if (d[i]) cnt++;
            }

            long long mx = 0, sum = 0;
            for (int i = l; i <= r; ++ i)
            {
                mx = max(mx, points[i]);
                if (d[i])
                {
                    if (cnt % 2) sum += mx;
                    mx = 0;
                    cnt++;
                }
            }
            if (cnt % 2) sum += mx;
            cout << sum << endl;
        }
    }

    return 0;
}
