//蒟蒻一枚
#include<bits/stdc++.h>
#define re register
#define il inline
#define ls(xx) tr[xx].son[0]
#define rs(xx) tr[xx].son[1]
#define int LL
using namespace std;
typedef long long LL;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
return x*f;
}
const int N=1e5+100;
int n,m,root,tot,ad[N],inf=2e9+100;
struct splay_tree{
int son[2],fa;
LL val,siz,maxx;
int add,rev;
void clean(){
son[0]=son[1]=fa=0,maxx=-inf,siz=0;
}
}tr[N];
il void pushup(int x){
//if(x)return;
tr[x].siz=ls(x)?tr[ls(x)].siz:0+rs(x)?tr[rs(x)].siz:0+1;
tr[x].maxx=max(tr[ls(x)].maxx,tr[rs(x)].maxx);
}
il int build(int l,int r,int fa){
if(l>r)return 0;
int x=++tot,mid=(l+r)>>1;
tr[x].fa=fa;
tr[x].maxx=tr[x].val=ad[mid];
tr[x].siz=1;
tr[x].son[0]=build(l,mid-1,x);
tr[x].son[1]=build(mid+1,r,x);
pushup(x);
return x;
}
il void rotate(int x){
int y=tr[x].fa,z=tr[y].fa;
int k=(tr[y].son[1]==x);
tr[z].son[tr[z].son[1]==y]=x;
tr[x].fa=z;
tr[y].son[k]=tr[x].son[k^1];
tr[tr[x].son[k^1]].fa=y;
tr[x].son[k^1]=y;
tr[y].fa=x;
pushup(y),pushup(x);
}
il splay(int x,int goal){
while(x!=goal){
int y=tr[x].fa,z=tr[y].fa;
// cout<<x<<" "<<y<<" "<<z<<endl;
if(z!=goal) ((tr[y].son[1]==x)^(tr[z].son[1]==y))?rotate(x):rotate(y);
rotate(x);
// cout<<1<<endl;
}
if(!goal)root=x;
}
il void pushdown(int x){
if(tr[x].add){
tr[ls(x)].add=tr[rs(x)].add=tr[x].add;
tr[x].maxx+=tr[x].add;
tr[x].add=0;
}
if(tr[x].rev){
tr[ls(x)].rev^=1,tr[rs(x)].rev^=1;
swap(tr[x].son[0],tr[x].son[1]);
tr[x].rev=0;
}
}
il int find(int x){
int u=root;
while(1){
pushdown(u);
if(tr[tr[u].son[0]].siz>=x) u=tr[u].son[0];
else if(tr[tr[u].son[0]].siz+1==x)return u;
else x-=tr[tr[u].son[0]].siz+1,u=tr[u].son[1];
}
}
il void reverse(){
int l=read()+1,r=read()+1;
int x=find(l-1),y=find(r+1);
splay(x,0),splay(y,x);
tr[ls(rs(root))].rev^=1;
}
il void Add(){
int l=read(),r=read(),v=read();
l++,r++;
int x=find(l-1),y=find(r+1);
// cout<<x<<" "<<y<<endl;
splay(x,0),splay(y,x);
tr[ls(rs(root))].add+=v;
}
il void Max(){
int l=read(),r=read();
l++,r++;
int x=find(l-1),y=find(r+1);
splay(x,0),splay(y,x);
cout<<tr[ls(rs(root))].maxx<<'\n';
}
il void output(int x){
pushdown(x);
cout<<x<<" "<<tr[x].val<<" "<<ls(x)<<" "<<rs(x)<<endl;
if(tr[x].son[0])output(tr[x].son[0]);
if(tr[x].son[1])output(tr[x].son[1]);
}
void debug(){
output(root);putchar('\n');
}
signed main(){
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
n=read(),m=read();
ad[1]=ad[n+2]=-inf;
root=build(1,n+2,0);
/* cout<<root<<endl;
debug();
tr[0].clean();
splay(6,0);
debug();*/
while(m--){
int opt=read();
if(opt==1) Add();
if(opt==2) reverse();
if(opt==3) Max();
output(root);putchar('\n');
}
return 0;
}
为什么我的splay照着板子打的splay操作还会陷入死循环呢?求大佬解答,一定关注