Given a one dimensional integer array A of length N. We need Q queries each of one of following types:
NOTE : M is fixed to be 10^9 + 7
Query 1 : 1 x y v : It means adding v to all element from x to y in 1 base indexed array and then take them modulo M.
for (i = x; i <= y; i++)
A[i] += v;
A[i] %= M;
Query 2 : 2 x y v : It means multiplying v to all element from x to y in 1 base indexed array and then take them modulo M.
for (i = x; i <= y; i++)
A[i] *= v
A[i] %= M
Query 3 : 3 x y v : It means substituting v to all element from x to y in 1 base indexed array.
for (i = x; i <= y; i++)
A[i] = v
Query 4 : 4 x y : This is a report query which needs to find the sum of the values in A from x to y, i.e.,
sum = 0;
for (i = x; i <= y; i++)
sum += A[i]
sum %= M
Output sum.
Now how to handle these queries ? I know to handle queries if it were addition and sum queries with segment tree. But have no idea for this one. Please help me to solve this problem.
Constraints : 1 ≤ N,Q ≤ 10^5 and 1 ≤ Initial value of A[i],v ≤ 10^9