A10274 | Fence Divercity
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of $n$ consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the $i$ -th board to the left is $h_{i}$ .
Today Vasily decided to change the design of the fence he had built, by cutting his top connected part so that the fence remained good. The cut part should consist of only the upper parts of the boards, while the adjacent parts must be interconnected (share a non-zero length before cutting out of the fence).
You, as Vasily's curious neighbor, will count the number of possible ways to cut exactly one part as is described above. Two ways to cut a part are called distinct, if for the remaining fences there is such $i$ , that the height of the $i$ -th boards vary.
As Vasily's fence can be very high and long, get the remainder after dividing the required number of ways by $1000000007$ $(10^{9}+7)$ .
Today Vasily decided to change the design of the fence he had built, by cutting his top connected part so that the fence remained good. The cut part should consist of only the upper parts of the boards, while the adjacent parts must be interconnected (share a non-zero length before cutting out of the fence).
You, as Vasily's curious neighbor, will count the number of possible ways to cut exactly one part as is described above. Two ways to cut a part are called distinct, if for the remaining fences there is such $i$ , that the height of the $i$ -th boards vary.
As Vasily's fence can be very high and long, get the remainder after dividing the required number of ways by $1000000007$ $(10^{9}+7)$ .
输入格式
The first line contains integer $n$ ( $1<=n<=1000000$ ) — the number of boards in Vasily's fence.
The second line contains $n$ space-separated numbers $h_{1},h_{2},...,h_{n}$ ( $1<=h_{i}<=10^{9}$ ), where $h_{i}$ equals the height of the $i$ -th board to the left.
The second line contains $n$ space-separated numbers $h_{1},h_{2},...,h_{n}$ ( $1<=h_{i}<=10^{9}$ ), where $h_{i}$ equals the height of the $i$ -th board to the left.
输出格式
Print the remainder after dividing $r$ by $1000000007$ , where $r$ is the number of ways to cut exactly one connected part so that the part consisted of the upper parts of the boards and the remaining fence was good.
输入输出样例
输入 #1
2 1 1
输出 #1
0
输入 #2
3 3 4 2
输出 #2
13
From the fence from the first example it is impossible to cut exactly one piece so as the remaining fence was good.
All the possible variants of the resulting fence from the second sample look as follows (the grey shows the cut out part):

All the possible variants of the resulting fence from the second sample look as follows (the grey shows the cut out part):

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted