Codeforces Round 609 (Div. 1)
C
K Integers
Codeforces
2300
原题
← BD →
翻译中…

You are given a permutation $p_1, p_2, \ldots, p_n$.

翻译中…

In one move you can swap two adjacent values.

翻译中…

You want to perform a minimum number of moves, such that in the end there will exist a subsegment $1,2,\ldots, k$, in other words in the end there should be an integer $i$, $1 \leq i \leq n-k+1$ such that $p_i = 1, p_{i+1} = 2, \ldots, p_{i+k-1}=k$.

翻译中…

Let $f(k)$ be the minimum number of moves that you need to make a subsegment with values $1,2,\ldots,k$ appear in the permutation.

翻译中…

You need to find $f(1), f(2), \ldots, f(n)$.

翻译中…

Input

翻译中…

The first line of input contains one integer $n$ ($1 \leq n \leq 200\,000$): the number of elements in the permutation.

翻译中…

The next line of input contains $n$ integers $p_1, p_2, \ldots, p_n$: given permutation ($1 \leq p_i \leq n$).

翻译中…

Output

翻译中…

Print $n$ integers, the minimum number of moves that you need to make a subsegment with values $1,2,\ldots,k$ appear in the permutation, for $k=1, 2, \ldots, n$.

翻译中…

样例

Input #1
5
5 4 3 2 1
Output #1
0 1 3 6 10
InputCopy OutputCopy
Input #2
3
1 2 3
Output #2
0 0 0
InputCopy OutputCopy
题目信息
题号
1268C
时间限制
3 s
内存限制
256 MB
标签
二分
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。