A840.262144 Revisited--Platinum

NOI/NOI+/CTSC

USACO

通过率:0%

时间限制:1.00s

内存限制:128MB

题目描述

Bessie likes downloading games to play on her cell phone, even though she does
find the small touch screen rather cumbersome to use with her large hooves.
She is particularly intrigued by the current game she is playing. The game
starts with a sequence of NN positive integers a1,a2,…,aNa_1,a_2,\ldots,a_N. In one move, Bessie can take
two adjacent numbers and replace them with a single number equal to one
greater than the maximum of the two (e.g., she might replace an adjacent pair
(5,7)(5,7) with an 88). The game ends after N−1N-1 moves, at which point only a
single number remains. The goal is to minimize this final number.
Bessie knows that this game is too easy for you. So your job is not just to
play the game optimally on aa, but for every contiguous subsequence of aa.
Output the sum of the minimum possible final numbers over all
N(N+1)2\frac{N(N+1)}{2} contiguous subsequences of aa.

输入格式

第一行包含一个整数 NN。
第二行包含 NN 个以空格分隔的整数 a1,a2,…,aNa_1,a_2,\ldots,a_N,表示初始序列。

输出格式

输出一个整数,表示所有连续子序列对应的最小可能最终值之和。

输入输出样例

  • 输入#1

    6
    1 3 1 2 1 10
    

    输出#1

    115
    

说明/提示

对任意连续子序列,记其经过若干次操作后能够得到的最小最终数值为该子序列的最优值。输出所有连续子序列最优值之和。

数据范围

所有数据满足 2≤N≤2621442\le N\le262144,且 1≤ai≤1061\le a_i\le10^6。

测试点编号 NN
01 N=6N=6(样例)
02–03 N≤300N\le300
04–05 N≤3000N\le3000
06–25 N≤262144N\le262144

此外,06–08 号测试点均满足 ai≤40a_i\le40;09–11 号测试点的序列单调不减;12–25 号测试点没有额外限制。

样例中共有 6⋅7/2=216\cdot7/2=21 个连续子序列。以 [1,3,1,2,1][1,3,1,2,1] 为例,一种可得到最小最终值 5 的操作顺序是:
[1,3,1,2,1] → [4,1,2,1] → [4,1,3] → [4,4] → [5]。

该样例中各连续子序列的最小最终值为:
(1,1):1, (1,2):4, (1,3):5, (1,4):5, (1,5):5, (1,6):11;
(2,2):3, (2,3):4, (2,4):4, (2,5):5, (2,6):11;
(3,3):1, (3,4):3, (3,5):4, (3,6):11;
(4,4):2, (4,5):3, (4,6):11;
(5,5):1, (5,6):11;
(6,6):10。

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

首页