const int maxn=1e5+100;
int tol=0,rt[maxn*60],lson[maxn*60],rson[maxn*60],lz[maxn*60];
ll v[maxn*60];
void push_up(int x){
v[x]=max(v[lson[x]],v[rson[x]]);
}
void push_down(int x,int len){
if(lz[x]){
v[lson[x]]+=(len>>1)*lz[x];
v[rson[x]]+=(len-(len>>1))*lz[x];
lz[lson[x]]=lz[x];
lz[rson[x]]=lz[x];
lz[x]=0;
}
}
void build(int &x,int l,int r){
x=++tol;
//cout<<x<<" "<<l<<' '<<r<<endl;
if(l==r){
v[x]=1e15;
return ;
}
int mid=(l+r)>>1;
build(lson[x],l,mid);
build(rson[x],mid+1,r);
push_up(x);
}
void update(int pos,int l,int r,int &x,int la,ll val){
x=++tol;
lson[x]=lson[la],rson[x]=rson[la],v[x]=v[la];
if(l==r){
v[x]=min(v[x],val);
return ;
}
//push_down()
int mid=(l+r)>>1;
if(pos<=mid) update(pos,l,mid,lson[x],lson[la],val);
else update(pos,mid+1,r,rson[x],rson[la],val);
push_up(x);
}
ll query(int L,int R,int l,int r,int x){
if(L<=l&&R>=r){
return v[x];
}
//push_down();
int mid=(l+r)>>1;
if(R<=mid) {
return query(L,R,l,mid,lson[x]);
}
else if(L>mid){
return query(L,R,mid+1,r,rson[x]);
}
return max(query(L,R,l,mid,lson[x]),query(L,R,mid+1,r,rson[x]));
}
主席树部分模版
最新推荐文章于 2019-08-28 21:20:57 发布