CF1268C.K Integers

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a permutation p1,p2,…,pnp_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,…,k1,2,\ldots, k, in other words in the end there should be an integer ii, 1≤i≤n−k+11 \leq i \leq n-k+1 such that pi=1,pi+1=2,…,pi+k−1=kp_i = 1, p_{i+1} = 2, \ldots, p_{i+k-1}=k.

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

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

给你一个排列 p1,p2,…,pnp_1, p_2, \ldots, p_n。

每次操作你可以交换两个相邻的元素。

你希望执行最少次数的操作,使得最终排列中存在一个连续子段 1,2,…,k1,2,\ldots, k;换句话说,最终应存在一个整数 ii(满足 1≤i≤n−k+11 \leq i \leq n-k+1),使得 pi=1,pi+1=2,…,pi+k−1=kp_i = 1, p_{i+1} = 2, \ldots, p_{i+k-1}=k。

令 f(k)f(k) 表示使排列中出现值为 1,2,…,k1,2,\ldots,k 的连续子段所需的最少操作次数。

你需要求出 f(1),f(2),…,f(n)f(1), f(2), \ldots, f(n)。

输入格式

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

The next line of input contains nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n: given permutation (1≤pi≤n1 \leq p_i \leq n).

输入的第一行包含一个整数 nn(1≤n≤200 0001 \leq n \leq 200\,000):排列中元素的个数。

输入的第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \ldots, p_n:给定的排列(1≤pi≤n1 \leq p_i \leq n)。

输出格式

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

输出 nn 个整数,分别表示:对于 k=1,2,…,nk=1, 2, \ldots, n,使排列中出现一个值为 1,2,…,k1,2,\ldots,k 的连续子段(subsegment)所需的最少操作次数。

输入输出样例

  • 输入#1

    5
    5 4 3 2 1

    输出#1

    0 1 3 6 10
  • 输入#2

    3
    1 2 3

    输出#2

    0 0 0

输入解题思路,AI测评打分。不知道怎么写?

首页