CF1268C.K Integers
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation p1,p2,…,pn.
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,…,k, in other words in the end there should be an integer i, 1≤i≤n−k+1 such that pi=1,pi+1=2,…,pi+k−1=k.
Let f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation.
You need to find f(1),f(2),…,f(n).
给你一个排列 p1,p2,…,pn。
每次操作你可以交换两个相邻的元素。
你希望执行最少次数的操作,使得最终排列中存在一个连续子段 1,2,…,k;换句话说,最终应存在一个整数 i(满足 1≤i≤n−k+1),使得 pi=1,pi+1=2,…,pi+k−1=k。
令 f(k) 表示使排列中出现值为 1,2,…,k 的连续子段所需的最少操作次数。
你需要求出 f(1),f(2),…,f(n)。
输入格式
The first line of input contains one integer n (1≤n≤200000): the number of elements in the permutation.
The next line of input contains n integers p1,p2,…,pn: given permutation (1≤pi≤n).
输入的第一行包含一个整数 n(1≤n≤200000):排列中元素的个数。
输入的第二行包含 n 个整数 p1,p2,…,pn:给定的排列(1≤pi≤n)。
输出格式
Print n integers, the minimum number of moves that you need to make a subsegment with values 1,2,…,k appear in the permutation, for k=1,2,…,n.
输出 n 个整数,分别表示:对于 k=1,2,…,n,使排列中出现一个值为 1,2,…,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测评打分。不知道怎么写?