过样例了。。。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define int long long
#define endl puts("")
using namespace std;
const int N=1e6+10;
const int inf=0x3f3f3f3f3f3f3f3f;
struct node
{
int ch[2],fa,val;
int siz,cnt,tag;
int maxx,add;
}t[N];
int n,m,root;
int e[N];
char eof_flag;inline char read(int*s){if(eof_flag)return 0;int k=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9')){if(c==EOF){eof_flag=1;return 0;}c=getchar();}f=(c=='-')?-1:1;k=(c=='-')?0:(c^48);c=getchar();while(c>='0'&&c<='9')k=(k<<1)+(k<<3)+(c^48),c=getchar();if(c==EOF)eof_flag=1;(*s)=f>0?k:-k;return 1;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');return;}
inline void push_down(int u)
{
int lson=t[u].ch[0],rson=t[u].ch[1],add=t[u].add;
if (t[u].tag)
{
if (lson) t[lson].tag^=1,swap(t[lson].ch[0],t[rson].ch[1]);
if (rson) t[rson].tag^=1,swap(t[lson].ch[0],t[rson].ch[1]);
t[u].tag=0;
}
if (t[u].add)
{
if (lson) t[lson].add+=add,t[lson].val+=add,t[lson].maxx+=add;
if (rson) t[rson].add+=add,t[rson].val+=add,t[rson].add+=add;
t[u].add=0;
}
return ;
}
inline void push_up(int u)
{
int lson=t[u].ch[0],rson=t[u].ch[1];
t[u].siz=1;
if (lson) t[u].siz+=t[lson].siz,t[u].maxx=max(t[lson].maxx,t[u].val);
if (rson) t[u].siz+=t[rson].siz,t[u].maxx=max(t[u].val,t[rson].maxx);
return ;
}
inline void rotate(int u)
{
int v=t[u].fa;
int w=t[v].fa;
int k=(t[v].ch[1]==u);
t[w].ch[t[w].ch[1]==v]=u;
t[u].fa=w;
t[v].ch[k]=t[u].ch[k^1];
t[t[u].ch[k^1]].fa=v;
t[u].ch[k^1]=v;
t[v].fa=u;
push_up(v),push_up(u);
return ;
}
inline void splay(int u,int goal)
{
while (t[u].fa!=goal)
{
int v=t[u].fa;
int w=t[v].fa;
if (w!=goal) ((t[w].ch[1]==v)^(t[v].ch[1]==u))?rotate(u):rotate(v);
rotate(u);
}
if (!goal) root=u;
return ;
}
inline int find_rank(int x)
{
int u=root;
if (t[u].siz<x) return 0;
while (1)
{
push_down(u);
int lson=t[u].ch[0];
if (t[lson].siz+1<x) x-=t[lson].siz+1,u=t[u].ch[1];
else
{
if (t[lson].siz>=x) u=lson;
else
{
splay(u,0);
return u;
}
}
}
}
inline void update_add(int l,int r,int w)
{
l=find_rank(l),r=find_rank(r+2);
splay(l,0),splay(r,l);
int u=t[t[root].ch[1]].ch[0];
t[u].add+=w;
t[u].val+=w;
t[u].maxx+=w;
push_up(t[root].ch[1]),push_up(root);
return ;
}
inline void update_reverse(int l,int r)
{
l=find_rank(l),r=find_rank(r+2);
splay(l,0),splay(r,l);
int u=t[t[root].ch[1]].ch[0];
t[u].tag^=1;
push_up(t[root].ch[1]),push_up(root);
return ;
}
inline int query_maxx(int l,int r)
{
l=find_rank(l),r=find_rank(r+2);
splay(l,0),splay(r,l);
return t[t[t[root].ch[1]].ch[0]].maxx;
}
inline int build(int l,int r,int fa)
{
if (l>r) return 0;
if (l==r)
{
t[l].add=t[l].tag=t[l].maxx=0;
t[l].siz=t[l].cnt=1;
t[l].fa=fa,t[l].val=0;
return l;
}
int mid=l+r>>1;
t[mid].ch[0]=build(l,mid-1,mid);
t[mid].ch[1]=build(mid+1,r,mid);
t[mid].add=t[mid].tag=t[mid].maxx=0;
t[mid].fa=fa,t[mid].val=0;
push_up(mid);
return mid;
}
signed main()
{
read(&n),read(&m);
e[1]=e[n+2]=t[0].maxx=-inf;
root=build(1,n+2,0);
while (m--)
{
int op,l,r,w;
read(&op),read(&l),read(&r);
if (op==1) read(&w),update_add(l,r,w);
if (op==2) update_reverse(l,r);
if (op==3) write(query_maxx(l,r)),endl;
}
return 0;
}