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

21136번 - Bitonic Ordering 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB118514554.217%

문제

Noah suggests the following card game: You are given a deck of cards, each with a distinct positive integer value written on it. The cards are shuffled and placed in a row. Your objective is to arrange the cards in the row so that the values are monotonically increasing initially, and then monotonically decreasing for the remainder of the sequence.

The only move that is allowed is that two neighboring cards may swap positions. Cards may only swap positions if they are adjacent to each other.

Note that in the final ordered sequence, the initial increasing portion of the sequence may be empty (such that the whole sequence is in descending order). Likewise it is allowed for the decreasing portion of the sequence to be empty.

What is the fewest number of moves needed to get the cards arranged in the proper order?

입력

The first line of input contains a single integer $n$ (1ドル \le n \le 3 \cdot 10^5$), which is the number of cards.

Each of the next $n$ lines contains a single integer $c$ (1ドル \le c \le 10^9$). These are the cards, in their initial order. They will all be distinct.

출력

Output a single integer, which is the fewest number of moves needed to arrange the cards as specified.

제한

예제 입력 1

8
7
4
8
10
1
2
6
9

예제 출력 1

7

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2020 Southeast USA Regional Programming Contest C번

ICPC > Regionals > North America > Mid-Central Regional > 2020 Mid-Central Regional Programming Contest N번

ICPC > Regionals > North America > Pacific Northwest Regional > 2020 ICPC Pacific Northwest Region > Division 1 E번

ICPC > Regionals > North America > Pacific Northwest Regional > 2020 ICPC Pacific Northwest Region > Division 2 V번

ICPC > Regionals > North America > Mid-Atlantic Regional > 2020 Mid-Atlantic USA Regional Contest I번

ICPC > Regionals > North America > South Central USA Regional > 2020 South Central USA Regional Contest C번

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

출처

대학교 대회

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

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