这个模板修改起来比较简单
// 线段树的信息
const int N = 2e5 + 10,mod = 1e9 + 7;
int a[N];
struct info // 存储线段树的值
{
int size;
int num;
};
struct tag // 存储线段树的懒标记
{
int add;
int mul;
};
struct Node // 线段树
{
info val;
tag lazy;
}tr[N << 2];
int st_size; // 线段树的总区间大小
// 线段树的具体操作
info operator + (const info &l,const info &r) // pushup的操作
{
info c;
c.size = l.size + r.size;
c.num = (1ll * l.num + r.num) % mod;
return c;
}
info operator + (const info &v,const tag &t) // pushdown时,对子节点info的操作
{
info c;
c.size = v.size;
c.num = (1ll * v.num * t.mul + 1ll * v.size * t.add) % mod;
return c;
}
tag operator + (const tag &ts,const tag &tp) // pushdown时,对子节点tag的操作
{
tag c;
c.add = (1ll * ts.add * tp.mul + tp.add) % mod;
c.mul = 1ll * ts.mul * tp.mul % mod;
return c;
}
void pushup(int u)
{
tr[u].val = tr[u <&