Under construction

Still being built. Things may change

Fibonacci and Sequence and Queries

Time limit1sMemory limit1024 MB

Summary
Start with a zero array of length N; each query adds Fibonacci numbers F1..F(r-l+1) to positions l..r, and print the final array modulo 1e9+7.
Level

Medium7 of 10

Topics
Prefix sum, Math, Array, Dynamic programming
Solved
No attempts yet

Problem

The Fibonacci numbers start with 00 and 11. The 00-th Fibonacci number is 00, and the 11-st Fibonacci number is 11. From the 22-nd Fibonacci number onward, each is the sum of the two immediately preceding Fibonacci numbers. As a formula, Fn=Fn−2+Fn−1F_n = F_{n-2} + F_{n-1} (n≥2n \geq 2).

A single nn-th Fibonacci number is easy to compute with the recurrence above, but this problem is not so simple. You are given a sequence of length NN in which every value is 00. Write a program that prints the result after performing the following queries.

  • l r: add F1,F2,...,Fr−l+1F_1, F_2, ..., F_{r-l+1} to positions ll through rr of the sequence, respectively.

Input

The first line gives the size of the sequence, NN. (1≤N≤1 000 0001 \leq N \leq 1\ 000\ 000)

The second line gives the number of queries, QQ. (1≤Q≤100 0001 \leq Q \leq 100\ 000)

Starting from the third line, QQ lines each give the information ll, rr for a query. (1≤l≤r≤N1 \leq l \leq r \leq N)

Output

After applying all queries, print all numbers of the sequence separated by spaces. Since the numbers can get very large, print each number modulo 109+710^9+7.

Examples1

  1. Example 1

    Input
    10
    3
    1 10
    1 5
    5 6
    
    Expected output
    2 2 4 6 11 9 13 21 34 55