#include <iostream>
#include <vector>
#define ll long long
#define endl "\n"
using namespace std;

const ll maxn = 1e5+1;
ll n,q,br,i,t,p,a,l,r,br2,br3;
ll state[maxn],score[maxn],qu[maxn],qu2[maxn],qu3[maxn],used[maxn],numflips[maxn];
bool after[maxn];
vector<ll> use;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    cin >> n >> q;
    for(i=0;i<q;i++){
        cin >> t;
        if(t==1){
            cin >> p;
            p--;
            for(ll j=p+1;j<n;j++){
                state[j]++;
            }
            after[p]=true;
        }
        if(t==2){
            cin >> p;
            p--;
            for(ll j=p+1;j<n;j++){
                state[j]++;
            }
            after[p]=false;
        }
        if(t==3){
            cin >> p >> a;
            p--;
            score[p]+=a;
        }
        if(t==4){
            cin >> l >> r;
            l--;
            r--;
            ll currmax=0,sbor=0;
            for(ll j=l;j<=r;j++){
                currmax=max(score[j],currmax);
                if(after[j] or j==r){
                    //cout << j << " j currmax " << currmax << " l " << l << " r " << r << endl;
                    if(state[j]%2==1){
                        sbor+=currmax;
                    }
                    currmax=0;
                }
            }
            cout << sbor << endl;
        }
    }/*
    for(i=1;i<=n;i++){
        if(used[i]){
            use.push_back(i);
        }
    }
    for(ll z=0;z<br3;z++){
        if(qu2[z]==1){
            //cout << "111111111111111111111" << endl;
            for(ll j=0;j<use.size();j++){
                if(use[j]>qu[z]){
                    numflips[use[j]]++;
                    //cout << use[j] << " flip " << endl;
                }
            }
            /*for(ll j=0;j<use.size();j++){
                cout <<  use[j] << " flips at: " << numflips[use[j]] << endl;
            }
        }
        if(qu2[z]==3){
            score[qu[z]]+=qu3[z];
        }
        if(qu2[z]==4){
            if(numflips[qu[z]]%2==1){
                cout << score[qu[z]] << endl;
            }else{
                cout << 0 << endl;
            }
        }
    }*/
    /*
    if(br3*br>1e9){
        while(true);
    }*/
return 0;
}

