This page is still under construction.

Parts of this page are still being built. What you see may change.

Shortsighted

Interview

Time limit2sMemory limit512 MB

Summary
Start with a zero array; range-update queries add a triangular weight pattern to each position, and range-sum queries report the total modulo 1e9+7.
Level

Medium7 of 10

Topics
Prefix sum, Math, Implementation, Array
Solved
No attempts yet

Problem

While practicing for The 2019 ICPC Asia Jakarta Regional Contest, Budi stumbled upon an interesting problem on data structure topic. Unfortunately, he misread the problem, but he argues that the problem he thinks of is much more interesting than the original one, thus, this problem.

Let function f(L,R)f(L, R) on an array of integers A1..NA_{1..N} be defined as incrementing every element in the subarray Ai..jA_{i..j} each by 1 for all L≤i≤j≤RL \le i \le j \le R. In other words, function f(L,R)f(L, R) can be written as follows (in pseudocode).

function f(L, R):
  FOR i from L to R
    FOR j from i to R
      FOR k from i to j
        Ak = Ak + 1

Given an array AA of NN elements (initially Ai=0A_i = 0 for all i=1..Ni = 1..N), your task is to perform QQ queries on AA of the following types.

  • 1 L R — perform f(L,R)f(L, R) on AA.
  • 2 L R — output the sum of all AiA_i where L≤i≤RL \le i \le R.

Input

Input begins with a line containing two integers: NN QQ (1≤N,Q≤100 0001 \le N, Q \le 100\,000) representing the size of AA and the number of queries, respectively. The next QQ lines each contains a query of the following types.

  • 1 L R (1≤L≤R≤N1 \le L \le R \le N)
  • 2 L R (1≤L≤R≤N1 \le L \le R \le N)

There is at least one query of the second type.

Output

For each query of the second type in the same order as input, output in a line an integer representing the sum of all AiA_i where L≤i≤RL \le i \le R. As this output can be large, you need to modulo the output by 1 000 000 0071\,000\,000\,007.

Examples1

  1. Example 1

    Input
    9 7
    1 2 5
    1 4 9
    2 2 7
    1 3 3
    2 2 7
    1 1 5
    2 1 9
    
    Expected output
    60
    61
    112