#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
bool downwards(int a, int b){
    return a>b;
}
long long n, q, points[MAX], bestToRight[MAX], bestToLeft[MAX], best[MAX], ending[MAX];
bool divider[MAX], parity[MAX];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q;
bool fir=true;
for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1 || t==2){
        int p;
        cin>>p;
        p--;
        divider[p]=!divider[p];
    }
    if(t==3){
        long long c, a;
        cin>>c>>a;
        c--;
        points[c]+=a;
    }
    if(t==4){
        if(fir){
            bool curr=false;
            int ma=0, start=0;
            for(int i=0;i<n;i++){
                parity[i]=curr;
                if(parity[i]==1){
                    if(points[i]>ma){
                        ma=points[i];
                    }
                }
                if(divider[i]){
                    curr=!curr;
                    for(int j=start;j<=i;j++){
                        best[j]=ma;
                        ending[j]=i;
                    }
                    start=i+1;
                    ma=0;
                }
            }
            for(int j=start;j<n;j++){
                best[j]=ma;
                ending[j]=n-1;
            }
            start=i+1;
            ma=0;
            curr=false;
            for(int i=0;i<n;i++){
                if(curr==1){
                    if(points[i]>ma){
                        ma=points[i];
                    }
                    bestToRight[i]=ma;
                }
                if(divider[i]){
                    curr=!curr;
                    ma=0;
                }
            }
            ma=0;
            curr=parity[n-1];
            for(int i=n-1;i>0;i--){
                if(curr==1){
                    if(points[i]>ma){
                        ma=points[i];
                    }
                    bestToLeft[i]=ma;
                }
                if(divider[i-1]){
                    curr=!curr;
                    ma=0;
                }
            }
        }
        int l, r;
        cin>>l>>r;
        l--;
        r--;
        long long ans=0;
        int curr=l;
        if(parity[curr]==1){
            ans+=bestToLeft[curr];
        }
        curr=ending[curr]+1;
        while(ending[curr]<r){
            if(curr>n-1){
                break;
            }
            if(parity[curr]==0){
                curr=ending[curr]+1;
            }else{
                ans=ans+best[curr];
                curr=ending[curr]+1;
            }
        }
        if(parity[r]==1){
            ans+=bestToRight[r];
        }
        cout<<ans<<"\n";
        fir=false;
    }
}
return 0;
}

