跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0558. Problem E: Frosh Week

    ID: 564 传统题 10000ms 128MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>待分类整理状态难度待定难度共享题库高校与竞赛共享题英文题面题目来源题面语言

Problem E: Frosh Week

题目描述

Problem E: Frosh Week

During Frosh Week, students play various fun games to get to know each other and compete against other teams. In one such game, all the frosh on a team stand in a line, and are then asked to arrange themselves according to some criterion, such as their height, their birth date, or their student number. This rearrangement of the line must be accomplished only by successively swapping pairs of consecutive students. The team that finishes fastest wins. Thus, in order to win, you would like to minimize the number of swaps required.

输入格式

The first line of input contains one positive integer n, the number of students on the team, which will be no more than one million. The following n lines each contain one integer, the student number of each student on the team. No student number will appear more than once.

输出格式

Output a line containing the minimum number of swaps required to arrange the students in increasing order by student number.

样例 1

输入

3
3
1
2

输出

2

题目来源:Waterloo October 2, 2010;FPS 共享题包,题包内第 5 题。保留原作者与原赛事署名。