304343: CF830B. Cards Sorting

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Cards Sorting

题意翻译

桌子上有$n$ 张卡片排成一列,每张卡片上有一个数$a_i$ ($1\le a_i\le100000,a_i\in \mathbf{Z}$ )。 有一个人每次从卡片的最左端开始,依次向右看过去,如果当前这张牌是现在的全局最小值,那么将它移除,如果不是,那么将它放到序列的最右端。持续到序列为空为止。求他进行的这两种操作的总次数。 ### 输入 第一行$n$ ,第二行$n$ 个数$a_1,a_2\cdots a_n$ 。 ### 输出 总操作次数。 ### 数据范围 $1\le n,a_i\le 100000$

题目描述

Vasily has a deck of cards consisting of $ n $ cards. There is an integer on each of the cards, this integer is between $ 1 $ and $ 100000 $ , inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is. You are to determine the total number of times Vasily takes the top card from the deck.

输入输出格式

输入格式


The first line contains single integer $ n $ ( $ 1<=n<=100000 $ ) — the number of cards in the deck. The second line contains a sequence of $ n $ integers $ a_{1},a_{2},...,a_{n} $ ( $ 1<=a_{i}<=100000 $ ), where $ a_{i} $ is the number written on the $ i $ -th from top card in the deck.

输出格式


Print the total number of times Vasily takes the top card from the deck.

输入输出样例

输入样例 #1

4
6 3 1 2

输出样例 #1

7

输入样例 #2

1
1000

输出样例 #2

1

输入样例 #3

7
3 3 3 3 3 3 3

输出样例 #3

7

说明

In the first example Vasily at first looks at the card with number $ 6 $ on it, puts it under the deck, then on the card with number $ 3 $ , puts it under the deck, and then on the card with number $ 1 $ . He places away the card with $ 1 $ , because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are $ [2,6,3] $ . Then Vasily looks at the top card with number $ 2 $ and puts it away. After that the cards from top to bottom are $ [6,3] $ . Then Vasily looks at card $ 6 $ , puts it under the deck, then at card $ 3 $ and puts it away. Then there is only one card with number $ 6 $ on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at $ 7 $ cards.

Input

题意翻译

桌子上有$n$ 张卡片排成一列,每张卡片上有一个数$a_i$ ($1\le a_i\le100000,a_i\in \mathbf{Z}$ )。 有一个人每次从卡片的最左端开始,依次向右看过去,如果当前这张牌是现在的全局最小值,那么将它移除,如果不是,那么将它放到序列的最右端。持续到序列为空为止。求他进行的这两种操作的总次数。 ### 输入 第一行$n$ ,第二行$n$ 个数$a_1,a_2\cdots a_n$ 。 ### 输出 总操作次数。 ### 数据范围 $1\le n,a_i\le 100000$

加入题单

算法标签: