RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0499

Cow Frisbee

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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 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\).

Problem credits: Quanquan Liu

제약

SCORING

  • Test cases 1-3 satisfy \(N\le 5000\).
  • Test cases 4-11 satisfy no additional constraints.

Problem credits: Quanquan Liu

입력 형식

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
출력
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)
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2021-2022 > January > Silver

태그

평가 및 의견

Cow Frisbee

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Cow Frisbee

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8