#P8590. 『JROI-8』这是新历的朝阳,也是旧历的残阳

    ID: 9742 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创前缀和洛谷月赛双指针 two-pointer

『JROI-8』这是新历的朝阳,也是旧历的残阳

Background

1663764375173.png

The girl stands by the sea, gazing at the last glow of the setting sun.
"It has already passed, the year of the old calendar......"

Reprint authorization has been obtained.

Problem Description

Given a sequence {an}\{a_n\} where each term is not less than the previous term. For every positive integer mm with mkm \le k, ask: if we split the sequence aa into mm segments (empty segments are allowed), and then for the ii-th segment from left to right, add ii to every number in that segment, what is the maximum possible value of j=1naj2\sum\limits_{j=1}^n a_j^2 after the increment?

Each query is independent. That is, in each query, the value added to each number does not carry over to the next query.

For example, for the sequence {3,1,2,2}\{-3,1,2,2\}, if m=5m=5, one possible segmentation is [3][][1,2][][2][-3][][1,2][][2]. The resulting sequence after increment is 2,4,5,7-2,4,5,7, and then j=1naj2=94\sum\limits_{j=1}^n a_j^2=94.

Let the answer for m=im=i (i.e., the maximum j=1naj2\sum\limits_{j=1}^n a_j^2 in this case) be qiq_i. To be nice, you only need to output $\left(\sum\limits_{i=1}^k q_i\right) \bmod 998244353$. The standard solution is not based on this special output format, meaning it can compute each qiq_i independently.

Input Format

The first line contains two positive integers n,kn,k, as described.

The next line contains nn integers, representing {an}\{a_n\}.

Output Format

Output one integer, which is $\left(\sum\limits_{i=1}^k q_i\right) \bmod 998244353$.

4 3
-3 1 2 2
141

Hint

Sample Explanation

When m=1m=1, the optimal strategy is [3,1,2,2][-3,1,2,2], and q1=(2)2+22+32+32=26q_1=(-2)^2+2^2+3^2+3^2=26.

When m=2m=2, the optimal strategy is [3][1,2,2][-3][1,2,2], and q2=(2)2+32+42+42=45q_2=(-2)^2+3^2+4^2+4^2=45.

When m=3m=3, the optimal strategy is [3][][1,2,2][-3][][1,2,2], and q3=(2)2+42+52+52=70q_3=(-2)^2+4^2+5^2+5^2=70.

So $\left(\sum\limits_{i=1}^k q_i\right) \bmod 998244353=(q_1+q_2+q_3)\bmod 998244353=(26+45+70)\bmod 998244353=141$.

Constraints

Test Point ID Score nn\leq kk\leq ai\lvert a_i\rvert \leq Special Property
131\sim 3 1515 1212 10001000 None
464\sim 6 10001000
787\sim 8 1010 10610^6 10610^6 10710^7 ai0a_i\geq0
9129 \sim 12 2020 10001000 None
132013\sim 20 4040 10710^7

Translated by ChatGPT 5