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

19663번 - Mountains 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB156776552.000%

문제

Pengu the Penguin lives in Antartica with his penguin friends. Despite being flightless birds, they wish to experience the joy of soaring through the air. Pengu decides to fulfill their wishes through the power of technology - with gliders.

Luckily for Pengu, there are n mountains in the Transantartic Mountain Range. The mountains are labelled 1 to n and are arranged in a row from left to right. The ith mountain has height Hi.

Pengu decides to pick 3 mountains x, y and z. He plans to build a base station on mountain y and receiving stations on mountains x and z. Penguins will glide from mountain y to either mountain x or z. To acommodate more penguins while avoiding midair collisions, mountains x and z are to the left and right of mountain y respectively. Furthermore, mountains x and z must be strictly shorter than mountain y. Pengu is very meticulous and wants to consider all possible choices. Find the number of possible choices for (x, y, z) such that 1 ≤ x < y < z ≤ n, Hx < Hy and Hy > Hz.

입력

Your program must read from standard input. The first line contains an integer n, the number of mountains. The second line contains n integers, where the ith integer represents the height of the ith mountain Hi.

출력

Your program must print to standard output.

The output should contain a single integer on a single line, the total number of possible choices for (x, y, z).

제한

  • 3 ≤ n ≤ 3 × 105
  • 0 ≤ Hi ≤ 1018

예제 입력 1

5
0 1 1 0 1

예제 출력 1

2

There are 2 valid triplets: (1, 2, 4) and (1, 3, 4).

예제 입력 2

6
500 20 900 0 900 70

예제 출력 2

7

There are 7 valid triplets: (1, 3, 4), (1, 3, 6), (1, 5, 6), (2, 3, 4), (2, 3, 6), (2, 5, 6) and (4, 5, 6).

힌트

출처

Olympiad > National Olympiad in Informatics (Singapore) > Qualification > NOI 2020 Preliminary 1번

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

출처

대학교 대회

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

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