标记下放
void pushdown(int now,int l,int r,int mid)
{
if (delta[now]!=0)
{
tree[now<<1]+=delta[now]*(mid-l+1);
delta[now<<1]+=delta[now];
tree[(now<<1)+1]+=delta[now]*(r-mid);
delta[(now<<1)+1]+=delta[now];
delta[now]=0;
}
}
区间修改
void qjchange(int now,int l,int r,int ll,int rr,int v)
{
int mid=(l+r)/2;
if (ll<=l&&r<=rr)
{
tree[now]+=(r-l+1)*v;
delta[now]+=v;
return ;
}
pushdown(now,l,r,mid);
if (ll<=mid)
qjchange(now<<1,l,mid,ll,rr,v);
if (mid+1<=rr)
qjchange((now<<1)+1,mid+1,r,ll,rr,v);
tree[now]=tree[now<<1]+tree[(now<<1)+1];
}
区间求和
int qjsum(int now,int l,int r,int ll,int rr)
{
if (ll<=l&&r<=rr)
{
return tree[now];
}
int mid=(l+r)/2;
pushdown(now,l,r,mid);
int ans1=0;
if (ll<=mid)
ans1+=qjsum(now<<1,l,mid,ll,rr);
if (rr>mid)
ans1+=qjsum((now<<1)+1,mid+1,r,ll,rr);
return ans1;
}
点修改
void pointchange(int now,int l,int r,int point,int value)
{
if (l==r)
{
tree[now]=value;
return ;
}
int mid=(l+r)/2;
if (point<=mid)
pointchange(now<<1,l,mid,point,value);
else
pointchange((now<<1)+1,mid+1,r,point,value);
tree[now]=min(tree[now<<1],tree[(now<<1)+1]);
}
建树
void build(int now,int l,int r)
{
if (l==r)
{
tree[now]=a[l];
return;
}
int mid=(l+r)/2;
build(now<<1,l,mid);
build((now<<1)+1,mid+1,r);
tree[now]=min(tree[now<<1],tree[(now<<1)+1]);
}