前言
传送门 :
好久没写,线段树了,没想到被难到了
思路
区间操作 对应 懒标记
两个区间操作 即 两个懒标记
Q: 两个懒标记应该先计算哪个 ?
如果先计算加法再计算乘法,那么加法一定需要被乘数整除才行
因此先使用加法
对于每个数我们都看成
a
∗
b
+
c
a*b+c
a∗b+c
因此对于 乘法懒标记 我们可以
b
∗
m
u
l
b*mul
b∗mul
对于加法懒标记
c
∗
m
u
l
+
a
d
d
c*mul + add
c∗mul+add
然后就是不好写 QAQ
CODE
#include
using namespace std;
#define ll long long
#define ned '\n'
const int N = 1e5+10;
int n,p,m;
int w[N];
struct node
{
int l,r;
int sum,add,mul; ///两个懒标记
}tr[N*4];///四倍空间
void pushup(int u)
{
tr[u].sum = (tr[u>d;
modify(1,l,r,0,d);
}
else if(op == 2)
{
cin>>d;
modify(1,l,r,d,1);
}
else
cout
关注
打赏
