#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=50050,maxm=100050,inf=0x3fffffff;
int n,m;
struct node*null,*pt;
struct node{
node*ch[2];
int v,s,add,mx;
bool rev;
inline int cmp(int k) const{
k-=ch[0]->s;
if(k==1) return -1;
return k<=0?0:1;
}
inline void maintain(){
s=ch[0]->s+ch[1]->s+1;
mx=max(v,max(ch[0]->mx,ch[1]->mx));
}
inline void pushdown(){
if(rev){
rev=0;
ch[0]->rev^=1;
ch[1]->rev^=1;
swap(ch[0],ch[1]);
}
if(add){
if(ch[0]!=null){
ch[0]->add+=add;
ch[0]->v+=add;
ch[0]->mx+=add;
}
if(ch[1]!=null){
ch[1]->add+=add;
ch[1]->mx+=add;
ch[1]->v+=add;
}
add=0;
}
}
};
node*newnode(){
pt->ch[0]=null;
pt->ch[1]=null;
pt->mx=0;
pt->add=0;
pt->v=0;
pt->s=1;
pt->rev=0;
return pt++;
}
node*root;
node x[maxn];
void rotate(node*&o,int d)
{
node*k=o->ch[d^1];
o->ch[d^1]=k->ch[d];
k->ch[d]=o;
o->maintain();k->maintain();
o=k;
}
void splay(node*&o,int k)
{
o->pushdown();
int d=o->cmp(k);
if(d==-1) return;
if(d==1) k-=o->ch[0]->s+1;
node*p=o->ch[d];
p->pushdown();
int d2=p->cmp(k);
int k2=d2?k-p->ch[0]->s-1:k;
if(d2!=-1){
splay(p->ch[d2],k2);
d==d2?rotate(o,d^1):rotate(o->ch[d],d);
}
rotate(o,d^1);
}
node* build(int l,int r)
{
if(l>=r) return null;
int mid=(l+r)>>1;
node*o=newnode();
if(l<mid) o->ch[0]=build(l,mid);
if(mid+1<r) o->ch[1]=build(mid+1,r);
o->maintain();
return o;
}
int read()
{
char c;
int f=1,ans=0;
c=getchar();
while(!isdigit(c)){
if(c==‘-‘) f=-1;
c=getchar();
}
while(isdigit(c)){
ans=ans*10+c-‘0‘;
c=getchar();
}
return f*ans;
}
void init()
{
pt=x;
null=newnode();
null->v=-inf;
null->mx=-inf;
null->s=0;
root=build(0,n+2);
}
int main()
{
n=read(),m=read();
init();
while(m--){
int opt=read();
if(opt==1){
int l=read(),r=read(),delta=read();
splay(root,l);
splay(root->ch[1],r+1-root->ch[0]->s);
root->ch[1]->ch[0]->add+=delta;
root->ch[1]->ch[0]->v+=delta;
root->ch[1]->ch[0]->mx+=delta;
}else if(opt==2){
int l=read(),r=read();
if(l==r) continue;
splay(root,l);
splay(root->ch[1],r+1-root->ch[0]->s);
root->ch[1]->ch[0]->rev^=1;
}else{
int l=read(),r=read();
splay(root,l);
splay(root->ch[1],r+1-root->ch[0]->s);
printf("%d\n",root->ch[1]->ch[0]->mx);
}
}
return 0;
}