Yuanfang is puzzled with the question below:
There are n integers, a
1, a
2, …, a
n. The initial values of them are 0. There are four kinds of operations.
Operation 1: Add c to each number between a
x and a
y inclusive. In other words, do transformation a
k<---a
k+c, k = x,x+1,…,y.
Operation 2: Multiply c to each number between a
x and a
y inclusive. In other words, do transformation a
k<---a
k×c, k = x,x+1,…,y.
Operation 3: Change the numbers between a
x and a
y to c, inclusive. In other words, do transformation a
k<---c, k = x,x+1,…,y.
Operation 4: Get the sum of p power among the numbers between a
x and a
y inclusive. In other words, get the result of a
x
p+a
x+1
p+…+a
y
p.
Yuanfang has no idea of how to do it. So he wants to ask you to help him.
InputThere are no more than 10 test cases.
For each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 <= n, m <= 100,000.
Each the following m lines contains an operation. Operation 1 to 3 is in this format: "1 x y c" or "2 x y c" or "3 x y c". Operation 4 is in this format: "4 x y p". (1 <= x <= y <= n, 1 <= c <= 10,000, 1 <= p <= 3)
The input ends with 0 0.
OutputFor each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007.Sample Input
5 5
3 3 5 7
1 2 4 4
4 1 5 2
2 2 5 8
4 3 5 3
0 0
Sample Output
307
7489
这道题有三种询问分别问区间和 平分的区间和 立方的区间和 有三种修改的方法 分别是 add 增加 mul 乘 sett 数值代替
所以要有三个lazy标记 当sett出现时 把 add mul标记都取消 当mul 出现时 如果有add标记 add变为 add*mul
所以在pushdown的过程中 先sett 在mul 最后 add
对于 set 和 mul 来说 平分和 和 立方和比较好求 对于add来说
平方和这样来推:(a + c)2 = a2 + c2 + 2ac , 即sum2[rt] = sum2[rt] + (r - l + 1) * c * c + 2 * sum1[rt] * c;
立方和这样推:(a + c)3 = a3 + c3 + 3a(a2 + ac) , 即sum3[rt] = sum3[rt] + (r - l + 1) * c * c * c + 3 * c * (sum2[rt] + sum1[rt] * c);
几个注意点:add标记取消的时候是置0,mul标记取消的时候是置1;在PushDown()中也也要注意取消标记,如set操作中取消add和mul,mul操作中更新add; 在add操作中要注意sum3 , sum2 , sum1的先后顺序,一定是先sum3 , 然后sum2 , 最后sum1; int容易爆,还是用LL要保险一点;
#include
#include
#include