#include<iostream>
#include<vector>
#include<set>
using namespace std;

long long broiMesta;
long long broiZaqvki;

long long tochki[100010];

struct DanniZaVarha{
    long long broiPrPrediNego;
    long long otKadeObhv;
    long long doKadeObhv;
    long long lqvoDete;
    long long dqsnoDete;
};

vector<DanniZaVarha> varhove;
long long korenNomer = -1;

long long daiNovVrah(DanniZaVarha novVrah){
    varhove.push_back(novVrah);
    return varhove.size() - 1;
}

long long postroiDarvo(long long otKade, long long doKade){
    if(otKade == doKade){
        return daiNovVrah({0, otKade, doKade, -1, -1});
    }

    long long lqvoDete = postroiDarvo(otKade, (otKade + doKade)/2);
    long long dqsnoDete = postroiDarvo((otKade + doKade)/2 + 1, doKade);

    return daiNovVrah({0, otKade, doKade, lqvoDete, dqsnoDete});
}

void update(long long segashenVrah, long long otKade, long long doKade, long long sKolko){
    if(segashenVrah == -1 || varhove[segashenVrah].otKadeObhv > doKade || varhove[segashenVrah].doKadeObhv < otKade){
        return ;
    }
    if(otKade <= varhove[segashenVrah].otKadeObhv && doKade >= varhove[segashenVrah].doKadeObhv){
        varhove[segashenVrah].broiPrPrediNego += sKolko;
        return ;
    }

    update(varhove[segashenVrah].lqvoDete, otKade, doKade, sKolko);
    update(varhove[segashenVrah].dqsnoDete, otKade, doKade, sKolko);
}

long long query(long long segashenVrah, long long kade){
    if(segashenVrah == -1 || varhove[segashenVrah].doKadeObhv < kade || varhove[segashenVrah].otKadeObhv > kade){
        return 0;
    }
    if(varhove[segashenVrah].otKadeObhv == kade && varhove[segashenVrah].doKadeObhv == kade){
        return varhove[segashenVrah].broiPrPrediNego;
    }

    return varhove[segashenVrah].broiPrPrediNego +
            query(varhove[segashenVrah].lqvoDete, kade) +
            query(varhove[segashenVrah].dqsnoDete, kade);
}

vector<long long> otgovori;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>broiMesta>>broiZaqvki;

    korenNomer = postroiDarvo(0, broiMesta - 1);

    for(long long i = 0; i < broiZaqvki; i++){
        long long tip;

        cin>>tip;

        if(tip == 1){
            long long sledKoe;

            cin>>sledKoe;
            sledKoe--;


            update(korenNomer, sledKoe + 1, broiMesta - 1, 1);
        }else{
            if(tip == 2){
                long long sledKoe;

                cin>>sledKoe;
                sledKoe--;

                update(korenNomer, sledKoe + 1, broiMesta - 1, -1);
            }else{
                if(tip == 3){
                    long long koeMqsto;
                    long long kolkoTochki;

                    cin>>koeMqsto>>kolkoTochki;
                    koeMqsto--;

                    tochki[koeMqsto] += kolkoTochki;
                }else{
                    long long otKade;
                    long long doKade;
                    cin>>otKade>>doKade;

                    otKade--;
                    doKade--;

                    long long tukaOtg = 0;

                    long long naiGolqmoSega = 0;

                    for(int i = otKade; i <= doKade; i++){

                        long long tukaQuery = query(korenNomer, i);

                        //cout<<"pitame za index "<<i<<" i predi nego ima "<<tukaQuery<<endl;

                        if(tukaQuery%2 == 1){
                            naiGolqmoSega = max(naiGolqmoSega, tochki[i]);
                        }else{
                            tukaOtg += naiGolqmoSega;
                            naiGolqmoSega = 0;
                        }
                    }

                    tukaOtg += naiGolqmoSega;

                    otgovori.push_back(tukaOtg);

                    //cout<<tukaOtg<<endl;

                }
            }
        }
    }

    for(long long i = 0; i < (long long)otgovori.size(); i++){
        cout<<otgovori[i]<<endl;
    }

    return 0;
}
