#P8094. [USACO22JAN] Cow Frisbee S
[USACO22JAN] Cow Frisbee S
Problem Description
Farmer John has cows with heights . One day, the cows line up in some order to play frisbee. Let denote the cows' heights in this order (so is a permutation of ).
Two cows at positions and in the line can successfully throw a frisbee back and forth if and only if every cow between them has height less than .
Compute the sum of distances over all pairs of positions such that the two cows can successfully throw a frisbee back and forth. The distance between positions and is .
Input Format
The first line contains an integer . The second line contains , separated by spaces.
Output Format
Output the sum of distances between all pairs of positions where the cows can successfully throw a frisbee back and forth. Note that the integers in this problem may require a 64-bit integer type (for example, "long long" in C or C++).
7
4 3 1 2 5 6 7
24
Hint
【Sample Explanation】
In this example, the valid position pairs are:
(1, 2), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (4, 5), (5, 6), (6, 7)
【Constraints】
-
Testcases 1-3 satisfy .
-
Testcases 4-11 have no additional constraints.
Translated by ChatGPT 5
相关
在以下作业中: