AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC25-001.Interesting Mountains

Easy · 2 s · 256 MB

  • icpc
  • fpc
  • 2025

On your holiday trip to the mountains, you are amazed by the high quality of your Flashy Yellow Panorama Camera. After shooting a couple of nice photos during your hike, you decide to send the nicest one to your best friend. Sure enough, they immediately reply that they see all kinds of fancy patterns – but they are not talking about the beautiful snow-capped mountains: they have a more abstract view of the photo…

Since the heights of the nnn mountains in the panorama photo are unique, you can view these heights as a permutation of all numbers between 111 and nnn (inclusive). Your friend thinks that a formation of three (not necessarily consecutive) mountains is interesting, when the first mountain is higher than the third mountain, and the third mountain is higher than the second mountain. In other words, three mountains with indices iii, jjj, and kkk (1≤i<j<k≤n1 \leq i < j < k \leq n1≤i<j<k≤n) and respective heights hih_ihi​, hjh_jhj​, and hkh_khk​ are interesting, if and only if hi>hk>hjh_i > h_k > h_jhi​>hk​>hj​. How many interesting formations can you find in a given panorama photo?

As an example, consider the first sample input: only the tuples with indices (1,3,5)(1, 3, 5)(1,3,5) and (2,3,5)(2, 3, 5)(2,3,5) are interesting formations.

Giriş formatı

The input consists of:

• One line with an integer nnn (3≤n≤3⋅1053\leq n\leq 3\cdot 10^53≤n≤3⋅105), the number of mountains in the photo.

• One line with nnn integers h1,…,hnh_1,\ldots,h_nh1​,…,hn​ (1≤hi≤n1\leq h_i\leq n1≤hi​≤n for each iii), the heights of the mountains in the photo. It is guaranteed all values of hih_ihi​ are unique.

Çıxış formatı

Output the number of interesting formations in the panorama photo.

Qeyd

Source: Freshmen Programming Contest 2025 · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license. · 14 of the 37 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

5
3 4 1 5 2

Çıxış #1

2

Giriş #2

3
3 1 2

Çıxış #2

1

Giriş #3

3
2 1 3

Çıxış #3

0

Giriş #4

11
5 9 10 11 1 2 3 4 6 7 8

Çıxış #4

69