CF1787I.Treasure Hunt

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Define the beauty value of a sequence b1,b2,…,bcb_1,b_2,\ldots,b_c as the maximum value of ∑i=1qbi+∑i=stbi\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i, where qq, ss, tt are all integers and s>qs \gt q or t≤qt\leq q. Note that bi=0b_i = 0 when i<1i \lt 1 or i>ci \gt c, ∑i=stbi=0\sum\limits_{i=s}^{t}b_i = 0 when s>ts \gt t.

For example, when b=[−1,−2,−3]b = [-1,-2,-3], we may have q=0q = 0, s=3s = 3, t=2t = 2 so the beauty value is 0+0=00 + 0 = 0. And when b=[−1,2,−3]b = [-1,2,-3], we have q=s=t=2q = s = t = 2 so the beauty value is 1+2=31 + 2 = 3.

You are given a sequence aa of length nn, determine the sum of the beauty value of all non-empty subsegments al,al+1,…,ara_l,a_{l+1},\ldots,a_r (1≤l≤r≤n1\leq l\leq r\leq n) of the sequence aa.

Print the answer modulo 998 244 353998\,244\,353.

定义序列 b1,b2,…,bcb_1,b_2,\ldots,b_c 的美观值为 ∑i=1qbi+∑i=stbi\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i 的最大值,其中 qq、ss、tt 均为整数,且满足 s>qs > q 或 t≤qt \leq q。注意:当 i<1i < 1 或 i>ci > c 时,bi=0b_i = 0;当 s>ts > t 时,∑i=stbi=0\sum\limits_{i=s}^{t}b_i = 0。

例如,当 b=[−1,−2,−3]b = [-1,-2,-3] 时,可取 q=0q = 0、s=3s = 3、t=2t = 2,此时美观值为 0+0=00 + 0 = 0;当 b=[−1,2,−3]b = [-1,2,-3] 时,可取 q=s=t=2q = s = t = 2,此时美观值为 1+2=31 + 2 = 3。

给定一个长度为 nn 的序列 aa,请计算序列 aa 的所有非空子段 al,al+1,…,ara_l,a_{l+1},\ldots,a_r(其中 1≤l≤r≤n1 \leq l \leq r \leq n)的美观值之和。

输出答案对 998 244 353998\,244\,353 取模的结果。

输入格式

Each test contains multiple test cases. The first line contains an integer TT (1≤T≤1041 \le T \le 10^4) — the number of test cases.

The first line contains an integer nn (1≤n≤1061\le n\le 10^6) — the length of aa.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (−106≤ai≤106-10^6 \leq a_i \leq 10^6) — the given sequence.

It's guaranteed that the sum of nn does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含一个整数 TT(1≤T≤1041 \le T \le 10^4)—— 测试用例的数量。

第一行包含一个整数 nn(1≤n≤1061\le n\le 10^6)—— 序列 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(−106≤ai≤106-10^6 \leq a_i \leq 10^6)—— 给定的序列。

保证所有测试用例中 nn 的总和不超过 10610^6。

输出格式

For each test case, print a line containing a single integer — the answer modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一行,包含一个整数——答案对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    4
    7
    80 59 100 -52 -86 -62 75
    8
    -48 -14 -26 43 -41 34 13 55
    1
    74
    20
    56 -60 62 13 88 -48 64 36 -10 19 94 25 -69 88 87 79 -70 74 -26 59

    输出#1

    5924
    2548
    148
    98887

说明/提示

In the second test case, for the subsequence [−26,43,−41,34,13][-26,43,-41,34,13], when q=5q=5, s=2s=2, t=5t=5, ∑i=1qbi+∑i=stbi=23+49=72\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i = 23 + 49 = 72.

In the third test case, there is only one non-empty consecutive subsequence [74][74]. When q=1q=1, s=1s=1, t=1t=1, ∑i=1qbi+∑i=stbi=148\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i = 148.

在第二个测试用例中,对于子序列 [−26,43,−41,34,13][-26,43,-41,34,13],当 q=5q=5、s=2s=2、t=5t=5 时,∑i=1qbi+∑i=stbi=23+49=72\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i = 23 + 49 = 72。

在第三个测试用例中,仅存在一个非空的连续子序列 [74][74]。当 q=1q=1、s=1s=1、t=1t=1 时,∑i=1qbi+∑i=stbi=148\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i = 148。

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

首页