You are given an array A=[A0,…,AN−1] consisting of N non-negative integers. You need to process Q queries, each of one of the following two types:
- 1 l r val: Assign the value val to each element Al,Al+1,…,Ar.
- 2 l r: Let A′ be the subarray A[l,r], i.e., A′i=Al+i for each i=0,…,r−l. Consider the set S of all arrays B of length r−l+1 such that 0≤Bi≤A′i for all 0≤i<r−l+1. Compute the sum of all contiguous subarrays of all arrays in S, and output the result modulo 109+7.
The first line contains two integers N and Q – the size of the array A and the number of queries, respectively.
The second line contains N integers, representing the elements of the array A.
Each of the next Q lines describes a query, either in the form 1 l r val or 2 l r.
Output data
For each query of type 2, print the computed sum on a separate line, modulo 109+7.
Constraints and clarifications
- 1≤N,Q≤200 000.
- 0≤Ai≤1 000 000 000 for each i=0,…,N−1.
- 0≤l≤r<N for every query.
- 0≤val≤1 000 000 000 for each query of type 1.
| # |
Score |
Constraints |
| 1 |
0 |
Examples. |
| 2 |
2 |
N≤7,Ai≤10,Q=1. |
| 3 |
3 |
N≤30,Ai≤100,Q=1. |
| 4 |
7 |
N≤60,Ai≤1000,Q≤60. |
| 5 |
17 |
N≤1000,Ai≤1000,Q=1. |
| 6 |
13 |
Q=1. |
| 7 |
25 |
All queries are of type 2. |
| 8 |
14 |
l=r for each query of type 1. |
| 9 |
19 |
No additional constraints. |
Example 1
stdin
3 5
3 3 3
2 0 0
2 0 1
2 0 2
1 2 2 1
2 0 2
stdout
6
96
960
384
Explanation
In the sample test case:
- In the first query, A[0,0]=[3]. Thus, S={[0],[1],[2],[3]}.
- The sums of all subarrays of all the arrays in S are 0, 1, 2 and 3 respectively. As such, the answer is 0+1+2+3=6.
- In the second query, A[0,1]=[3,3]. Thus, S={[0,0],[0,1],[0,2],[0,3], [1,0],[1,1],[1,2],[1,3], [2,0],[2,1],[2,2],[2,3], [3,0],[3,1],[3,2],[3,3]}.
- The sums of all subarrays of all the arrays in S are (0+0+0)+(0+1+1)+(0+2+2)+(0+3+3)+(1+1+0)+(1+2+1)+(1+3+2)+(1+4+3)+(2+2+0)+(2+3+1)+(2+4+2)+(2+5+3)+(3+3+0)+(3+4+1)+(3+5+2)+(3+6+3)=96.
- In the third query, A[0,2]=[3,3,3].
- In the fourth query, A[0,2]=[3,3,1].