Fibonacci and Sequence and Queries
Time limit1sMemory limit1024 MB
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 and . The -th Fibonacci number is , and the -st Fibonacci number is . From the -nd Fibonacci number onward, each is the sum of the two immediately preceding Fibonacci numbers. As a formula, ().
A single -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 in which every value is . Write a program that prints the result after performing the following queries.
l r: add to positions through of the sequence, respectively.
Input
The first line gives the size of the sequence, . ()
The second line gives the number of queries, . ()
Starting from the third line, lines each give the information , for a query. ()
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 .