原题链接--
https://acs.jxnu.edu.cn/problem/CF5Ehttps://acs.jxnu.edu.cn/problem/CF5E
Bindian Signalizing
4000ms 262144K
描述:
Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night.
In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other.
An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills.
译文:所有人都知道在很久以前伯兰的领土上生活着印第安部落。他们的首都被n座山围绕,形成了一个圈。在每座山上有个看守者,日夜看守着周围的地方。
为了防止看守者在山上生火造成危险.如果在连接两座山的圆弧上,没有比这两座山更高的山,那么一个看守者能看见另一个看守者。任意两座山有两个不同的圆弧相连,如果任意一个圆弧满足以上条件那么信号能被看见。举个例子,任意两个相邻的看守者之间的信号都能被互相看到。
一个重要的特征对于看守系统就是看守者之间能互相看到信号的对数。你应该通过所给山之间的高度来找到这个数量。
输入:
The first line of the input data contains an integer number n (3 ≤ n ≤ 106), n — the amount of hills around the capital. The second line contains n numbers — heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109.
译文:第一行输入包含一个整数n (3 ≤ n ≤ 106), n —围绕首都的山的数量。第二行包含n个数—山的高度按顺时针顺序排列。所有高度都是整数范围在1到109。
输出:
Print the required amount of pairs.
译文:打印出所要求的对数。
样例输入:
5 1 2 4 5 3
样例输出:
7