Codeforces Round 842 (Div. 2)
F
Wonderful Jump
Codeforces
2900
原题
← E→
翻译中…

You are given an array of positive integers $a_1,a_2,\ldots,a_n$ of length $n$.

翻译中…

In one operation you can jump from index $i$ to index $j$ ($1 \le i \le j \le n$) by paying $\min(a_i, a_{i + 1}, \ldots, a_j) \cdot (j - i)^2$ eris.

翻译中…

For all $k$ from $1$ to $n$, find the minimum number of eris needed to get from index $1$ to index $k$.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($2 \le n \le 4 \cdot 10^5$).

翻译中…

The second line contains $n$ integers $a_1,a_2,\ldots a_n$ ($1 \le a_i \le n$).

翻译中…

Output

翻译中…

Output $n$ integers — the $k$-th integer is the minimum number of eris needed to reach index $k$ if you start from index $1$.

翻译中…

Note

翻译中…

In the first example:

翻译中…
  • From $1$ to $1$: the cost is $0$,
  • From $1$ to $2$: $1 \rightarrow 2$ — the cost is $\min(2, 1) \cdot (2 - 1) ^ 2=1$,
  • From $1$ to $3$: $1 \rightarrow 2 \rightarrow 3$ — the cost is $\min(2, 1) \cdot (2 - 1) ^ 2 + \min(1, 3) \cdot (3 - 2) ^ 2 = 1 + 1 = 2$.
翻译中…

In the fourth example from $1$ to $4$: $1 \rightarrow 3 \rightarrow 4$ — the cost is $\min(1, 4, 4) \cdot (3 - 1) ^ 2 + \min(4, 4) \cdot (4 - 3) ^ 2 = 4 + 4 = 8$.

翻译中…

样例

Input #1
3
2 1 3
Output #1
0 1 2
InputCopy OutputCopy
Input #2
6
1 4 1 6 3 2
Output #2
0 1 2 3 6 8
InputCopy OutputCopy
Input #3
2
1 2
Output #3
0 1
InputCopy OutputCopy
Input #4
4
1 4 4 4
Output #4
0 1 4 8
InputCopy OutputCopy
题目信息
题号
1768F
时间限制
4 s
内存限制
128 MB
标签
动态规划
贪心

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