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