Average Counting Problem

Time limit: 4.5s Memory limit: 256MB Input: Output:

You are given an array A=[A0,,AN1]A = [A_0, \dots, A_{N−1}] consisting of NN non-negative integers. You need to process QQ queries, each of one of the following two types:

  • 1 l r val1\ l\ r\ val: Assign the value valval to each element Al,Al+1,,ArA_l, A_{l+1}, \dots , A_r.
  • 2 l r2\ l\ r: Let AA' be the subarray A[l,r]A[l, r], i.e., Ai=Al+i{A'}_i = A_{l+i} for each i=0,,rli = 0, \dots , r − l. Consider the set SS of all arrays BB of length rl+1r − l + 1 such that 0BiAi0 \leq B_i \leq {A'}_i for all 0i<rl+10 \leq i \lt r − l + 1. Compute the sum of all contiguous subarrays of all arrays in SS, and output the result modulo 109+7{10}^{9} + 7.

Input data

The first line contains two integers NN and QQ – the size of the array AA and the number of queries, respectively.

The second line contains NN integers, representing the elements of the array AA.

Each of the next QQ lines describes a query, either in the form 1 l r val1\ l\ r\ val or 2 l r2\ l\ r.

Output data

For each query of type 22, print the computed sum on a separate line, modulo 109+7{10}^{9} + 7.

Constraints and clarifications

  • 1N,Q200 0001 \leq N, Q \leq 200\ 000.
  • 0Ai1 000 000 0000 \leq A_i \leq 1\ 000\ 000\ 000 for each i=0,,N1i = 0, \dots, N − 1.
  • 0lr<N0 \leq l \leq r \lt N for every query.
  • 0val1 000 000 0000 \leq val \leq 1\ 000\ 000\ 000 for each query of type 11.
# Score Constraints
1 0 Examples.
2 2 N7,Ai10,Q=1N \leq 7, A_i \leq 10, Q = 1.
3 3 N30,Ai100,Q=1N \leq 30, A_i \leq 100, Q = 1.
4 7 N60,Ai1000,Q60N \leq 60, A_i \leq 1000, Q \leq 60.
5 17 N1000,Ai1000,Q=1N \leq 1000, A_i \leq 1000, Q = 1.
6 13 Q=1Q = 1.
7 25 All queries are of type 22.
8 14 l=rl = r for each query of type 11.
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]A[0, 0] = [3]. Thus, S={[0],[1],[2],[3]}S = \{[0], [1], [2], [3]\}.
    • The sums of all subarrays of all the arrays in SS are 00, 11, 22 and 33 respectively. As such, the answer is 0+1+2+3=60 + 1 + 2 + 3 = 6.
  • In the second query, A[0,1]=[3,3]A[0, 1] = [3, 3]. Thus, S={[0,0],[0,1],[0,2],[0,3]S = \{[0, 0], [0, 1], [0, 2], [0, 3], [1,0],[1,1],[1,2],[1,3][1, 0], [1, 1], [1, 2], [1, 3], [2,0],[2,1],[2,2],[2,3][2, 0], [2, 1], [2, 2], [2, 3], [3,0],[3,1],[3,2],[3,3]}[3, 0], [3, 1], [3, 2], [3, 3]\}.
    • The sums of all subarrays of all the arrays in SS 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(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]A[0, 2] = [3, 3, 3].
  • In the fourth query, A[0,2]=[3,3,1]A[0, 2] = [3, 3, 1].

Log in or sign up to be able to send submissions!