A11460 | Numbers on the blackboard
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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+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 $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$ .
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$ .
输入格式
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.
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.
输出格式
For each option output Sasha's result modulo $10^{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 $1$ and $2$ and writes $5$ . Then he erases $5$ and -3 and gets -1. -1 modulo $10^{9}+7$ is $10^{9}+6$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted