#P9325. [CCC 2023 S2] Symmetric Mountains

[CCC 2023 S2] Symmetric Mountains

题目描述

Rebecca is a tour guide and is trying to market the Rocky Mountains for her magazine. She recently took a beautiful picture consisting of NN mountains where the i-thi\text{-th} mountain from the left has a height hih_i. She will crop this picture for her magazine, by possibly removing some mountains from the left side of the picture and possibly removing some mountains from the right side of the picture. That is, a crop consists of consecutive mountains starting from the l-thl\text{-th} to the r-thr\text{-th} mountain where lrl \leq r. To please her magazine readers, Rebecca will try to find the most symmetric crop.

We will measure the asymmetric valueasymmetric\ value of a crop as the sum of the absolute difference for every pair of mountains equidistant from the midpoint of the crop. To help understand that definition, note that the absolute value of aa number vv, written as v|v|, is the non-negative value of v: for example 6=6\lvert -6 \rvert = 6 and 14=14|14| = 14. The asymmetric value of a crop is the sum of all hl+ihri|h_{l+i} - h_{r-i}| for 0irl20 \leq i \leq \frac{r-l}{2}. To put that formula in a different way, we pair up the mountains working from the outside in toward the centre, calculate the absolute difference in height of each of these pairs, and sum them up.

Because Rebecca does not know how wide the picture needs to be, for all possible crop lengths, find the asymmetric value of the most symmetric crop (the crop with the minimum asymmetric value).

输入格式

The first line consists of an integer NN, representing the number of mountains in the picture.

The second line consists of NN space-separated integers, where the i-thi\text{-th} integer from the left represents hih_i.

The following table shows how the available 15 marks are distributed:

Marks Bounds on NN Bounds on hih_i Additional Constraints
55 1N3001 \leq N \leq 300 0hi1050 \leq h_i \leq 10^5 None.
1N50001 \leq N \leq 5000 Height of mountains are in non-decreasing order from left to right.
None.

输出格式

Output on one line NN space-separated integers, where the i-thi\text{-th} integer from the left is the asymmetric value of the most symmetric picture of crops of length ii.

题目大意

Rebecca 有一张落基山脉的照片,上面排列着 N(1N5000)N(1\leq N \leq 5000) 座山,从左向右的第 ii 座山的高度是 hi(1hi105)h_i(1\leq h_i \leq 10^5)。Rebecca 截图保留照片的一个连续段,这张截图的不对称性定义为:处于截图上对称位置的山的高度差的绝对值之和(截图最左和最右的山的高度差,左数第二和右数第二的山的高度差,诸如此类的和)。

Rebecca 想要知道对于长度为 ii 的截图,拥有的最小不对称性。请你对于 1iN1\leq i \leq N,输出这个值。

7
3 1 4 1 5 9 2
0 2 0 5 2 10 10
4
1 3 5 6
0 1 3 7

提示

Explanation of Output for Sample Input 11:

We will show why the fifth value from the left is 22.Let us try to compute all the asymmetric values of crops with length 55.

The height of the mountains in the first crop is [3,1,4,1,5][3, 1, 4, 1, 5]. The asymmetric value of this crop is 35+11+44=2|3 - 5| + |1 - 1| + |4 - 4| = 2.

The height of the mountains in the second crop is [1,4,1,5,9][1, 4, 1, 5, 9]. The asymmetric value of this crop is 19+45+11=9|1 - 9| + |4 - 5| + |1 - 1| = 9.

The height of the mountains in the last crop is [4,1,5,9,2][4, 1, 5, 9, 2]. The asymmetric value of this crop is 42+19+55=10|4 - 2| + |1 - 9| + |5 - 5| = 10.

Hence, the most symmetric crop of length 55 is 22.

Explanation of Output for Sample Input 22:

This sample satisfies the second subtask. Note that the only crop of length 44 is [1,3,5,6][1, 3, 5, 6] which has asymmetric value of 16+35=7|1 - 6| + |3 - 5| = 7.

本题采用捆绑测试

  • Subtask 1(5 points):1N3001\leq N \leq 3000hi1050\leq h_i \leq 10^5

  • Subtask 2(5 points):1N50001 \leq N \leq 50000hi1050 \leq h_i \leq 10^5,保证山的高度从左到右单调不减。

  • Subtask 3(5 points):1N50001\leq N\leq 50000hi1050 \leq h_i \leq 10^5