Logo
(追記) (追記ここまで)

24492번 - Cow Frisbee 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB66134321753.448%

문제

Farmer John's $N$ cows ($N \leq 3 \times 10^5)$ have heights 1,ドル 2, \ldots, N$. One day, the cows are standing in a line in some order playing frisbee; let $h_1 \ldots h_N$ denote the heights of the cows in this order (so the $h$'s are a permutation of 1ドル \ldots N$).

Two cows at positions $i$ and $j$ in the line can successfully throw the frisbee back and forth if and only if every cow between them has height lower than $\min(h_i, h_j)$.

Please compute the sum of distances between all pairs of locations $i<j$ at which there resides a pair of cows that can successfully throw the frisbee back and forth. The distance between locations $i$ and $j$ is $j-i+1$.

입력

The first line of input contains a single integer $N$. The next line of input contains $h_1 \ldots h_N,ドル separated by spaces.

출력

Output the sum of distances of all pairs of locations at which there are cows that can throw the frisbee back and forth. Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

제한

예제 입력 1

7
4 3 1 2 5 6 7

예제 출력 1

24

힌트

The pairs of successful locations in this example are as follows:

(1, 2), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (4, 5), (5, 6), (6, 7)

출처

Olympiad > USA Computing Olympiad > 2021-2022 Season > USACO 2022 January Contest > Silver 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /