题目描述
Problem Description
There are $ N $ stacking blocks arranged in a row, each with a different height. By performing operations to swap adjacent pairs of blocks multiple times, you need to arrange them such that the tallest block is in the center and the heights decrease towards both ends. Specifically, let the height of the $ i $ -th block after rearrangement be $ Ai $, and let the position of the tallest block be $ T $. Then,
- $ A1 $ < $ A2 $ < ... < $ AT $ > ... > $ AN-1 $ > $ AN $
Find the minimum number of swaps required to achieve this arrangement.
Input Format
The input is given from the standard input in the following format:
$ N $ $ B1 $ $ B2 $ ... $ BN $
- The first line contains the number of blocks $N\ (1≦N≦10^5)$ separated by spaces.
- The second line contains the heights of the blocks $Bi\ (1≦Bi≦N)$ in the initial order.
- Note that all block heights are different. That is, $Bi≠Bj\ (i≠j)$ holds.
Output Format
Output the minimum number of swaps required to rearrange the blocks. End the output with a newline.
Sample Input and Output
Sample Input #1
4
2 4 1 3
Sample Output #1
1
Sample Input #2
5
2 4 1 3 5
Sample Output #2
3
Sample Input #3
6
1 2 4 3 5 6
Sample Output #3
1
Notes/Hints
Partial Points
This problem has two datasets, each with partial points assigned.
- If you solve dataset 1 with $ N≦100 $, you will be awarded 30 points.
- If you solve dataset 2 without additional constraints, you will be awarded an additional 70 points separately from the above dataset.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分