CF878E.Numbers on the blackboard

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A sequence of nn integers is written on a blackboard. Soon Sasha will come to the blackboard and start the following actions: let xx and yy be two adjacent numbers ( xx before yy ), then he can remove them and write x+2yx+2y 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 qq options, in the option ii he erases all numbers to the left of the lil_{i} -th number and all numbers to the right of rir_{i} -th number, i. e. all numbers between the lil_{i} -th and the rir_{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 109+710^{9}+7 .

输入格式

The first line contains two integers nn and qq ( 1<=n,q<=1051<=n,q<=10^{5} ) — the number of integers on the blackboard and the number of Nikita's options.

The next line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 109<=ai<=109-10^{9}<=a_{i}<=10^{9} ) — the sequence on the blackboard.

Each of the next qq lines contains two integers lil_{i} and rir_{i} ( 1<=li<=ri<=n1<=l_{i}<=r_{i}<=n ), describing Nikita's options.

输出格式

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

输入输出样例

  • 输入#1

    3 3
    1 2 3
    1 3
    1 2
    2 3
    

    输出#1

    17
    5
    8
    
  • 输入#2

    3 1
    1 2 -3
    1 3
    

    输出#2

    1000000006
    
  • 输入#3

    4 2
    1 1 1 -1
    1 4
    3 4
    

    输出#3

    5
    1000000006
    

说明/提示

In the second sample Nikita doesn't erase anything. Sasha first erases the numbers 11 and 22 and writes 55 . Then he erases 55 and -3 and gets -1. -1 modulo 109+710^{9}+7 is 109+610^{9}+6 .

首页