CF659G.Fence Divercity

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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 1 000 000 007 (109 + 7).

很久以前,瓦西里在他乡间别墅建造了一道很棒的篱笆。瓦西里称一道篱笆为“好的”,当且仅当它由 nn 块连续拼接的垂直木板组成,每块木板宽 1 厘米,高度(单位:厘米)为正整数。屋主记得从左往右第 ii 块木板的高度为 hih_i。

今天,瓦西里决定通过切下其顶部的一个连通部分来改变他已建篱笆的设计,使得切完后剩下的篱笆仍是“好的”。被切下的部分必须仅由各木板的上部构成,且相邻被切部分在切下前必须相互连通(即共享一段长度非零的公共边)。

作为瓦西里那充满好奇心的邻居,你需要计算出按上述方式恰好切下一块的可能方案数。若两种切割方式所得到的剩余篱笆中,存在某个 ii 使得第 ii 块木板的高度不同,则称这两种方式是不同的。

由于瓦西里的篱笆可能非常高且非常长,请将所求方案数对 1 000 000 0071\,000\,000\,007(即 109+710^9 + 7)取模后的余数作为答案。

输入格式

The first line contains integer n (1 ≤ n ≤ 1 000 000) — 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 ≤ 109), where h__i equals the height of the i-th board to the left.

第一行包含一个整数 nn(1≤n≤1 000 0001 \leq n \leq 1\,000\,000)——表示瓦西里围栏中木板的数量。

第二行包含 nn 个以空格分隔的整数 h1, h2, …, hnh_1,\,h_2,\,\dots,\,h_n(1≤hi≤1091 \leq h_i \leq 10^9),其中 hih_i 表示从左往右数第 ii 块木板的高度。

输出格式

Print the remainder after dividing r by 1 000 000 007, 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.

输出 rr 除以 1 000 000 0071\,000\,000\,007 的余数,其中 rr 表示恰好切下一块连通部分的方式数目,使得该部分由木板的上部构成,且剩余的栅栏是“良好”的。

输入输出样例

  • 输入#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):

从第一个样例的围栏中,无法恰好切下一块,使得剩余的围栏是“好”的。

第二个样例中所有可能得到的围栏如下所示(灰色部分表示被切掉的部分):

输入解题思路,AI测评打分。不知道怎么写?

首页