Codeforces Round 443 (Div. 1)
E
Numbers on the blackboard
Codeforces
3300
原题
← D→
翻译中…

A sequence of $*n*$ integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let $*x*$ and $*y*$ be two adjacent numbers ($*x*$ before $*y*$), then he can remove them and write $*x* + 2*y*$ instead of them. He will perform these operations until one number is left. Sasha likes big numbers and will get the biggest possible number.

翻译中…

Nikita wants to get to the blackboard before Sasha and erase some of the numbers. He has $*q*$ options, in the option $*i*$ he erases all numbers to the left of the $*l*_{*i*}$-th number and all numbers to the right of $*r*_{*i*}$-th number, i. e. all numbers between the $*l*_{*i*}$-th and the $*r*_{*i*}$-th, inclusive, remain on the blackboard. For each of the options he wants to know how big Sasha's final number is going to be. This number can be very big, so output it modulo $10^{9} + 7$.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*q*$ ($1 ≤ *n*, *q* ≤ 10^{5}$) — the number of integers on the blackboard and the number of Nikita's options.

翻译中…

The next line contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($- 10^{9} ≤ *a*_{*i*} ≤ 10^{9}$) — the sequence on the blackboard.

翻译中…

Each of the next $*q*$ lines contains two integers $*l*_{*i*}$ and $*r*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*$), describing Nikita's options.

翻译中…

Output

翻译中…

For each option output Sasha's result modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the second sample Nikita doesn't erase anything. Sasha first erases the numbers $1$ and $2$ and writes $5$. Then he erases $5$ and -3 and gets -1. -1 modulo $10^{9} + 7$ is $10^{9} + 6$.

翻译中…

样例

Input #1
3 3
1 2 3
1 3
1 2
2 3
Output #1
17
5
8
InputCopy OutputCopy
Input #2
3 1
1 2 -3
1 3
Output #2
1000000006
InputCopy OutputCopy
Input #3
4 2
1 1 1 -1
1 4
3 4
Output #3
5
1000000006
InputCopy OutputCopy
题目信息
题号
878E
时间限制
2 s
内存限制
512 MB
标签
组合数学
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。