CF1787I.Treasure Hunt
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Define the beauty value of a sequence b1,b2,…,bc as the maximum value of i=1∑qbi+i=s∑tbi, where q, s, t are all integers and s>q or t≤q. Note that bi=0 when i<1 or i>c, i=s∑tbi=0 when s>t.
For example, when b=[−1,−2,−3], we may have q=0, s=3, t=2 so the beauty value is 0+0=0. And when b=[−1,2,−3], we have q=s=t=2 so the beauty value is 1+2=3.
You are given a sequence a of length n, determine the sum of the beauty value of all non-empty subsegments al,al+1,…,ar (1≤l≤r≤n) of the sequence a.
Print the answer modulo 998244353.
定义序列 b1,b2,…,bc 的美观值为 i=1∑qbi+i=s∑tbi 的最大值,其中 q、s、t 均为整数,且满足 s>q 或 t≤q。注意:当 i<1 或 i>c 时,bi=0;当 s>t 时,i=s∑tbi=0。
例如,当 b=[−1,−2,−3] 时,可取 q=0、s=3、t=2,此时美观值为 0+0=0;当 b=[−1,2,−3] 时,可取 q=s=t=2,此时美观值为 1+2=3。
给定一个长度为 n 的序列 a,请计算序列 a 的所有非空子段 al,al+1,…,ar(其中 1≤l≤r≤n)的美观值之和。
输出答案对 998244353 取模的结果。
输入格式
Each test contains multiple test cases. The first line contains an integer T (1≤T≤104) — the number of test cases.
The first line contains an integer n (1≤n≤106) — the length of a.
The second line contains n integers a1,a2,…,an (−106≤ai≤106) — the given sequence.
It's guaranteed that the sum of n does not exceed 106.
每个测试包含多个测试用例。第一行包含一个整数 T(1≤T≤104)—— 测试用例的数量。
第一行包含一个整数 n(1≤n≤106)—— 序列 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(−106≤ai≤106)—— 给定的序列。
保证所有测试用例中 n 的总和不超过 106。
输出格式
For each test case, print a line containing a single integer — the answer modulo 998244353.
对于每个测试用例,输出一行,包含一个整数——答案对 998244353 取模的结果。
输入输出样例
输入#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], when q=5, s=2, t=5, i=1∑qbi+i=s∑tbi=23+49=72.
In the third test case, there is only one non-empty consecutive subsequence [74]. When q=1, s=1, t=1, i=1∑qbi+i=s∑tbi=148.
在第二个测试用例中,对于子序列 [−26,43,−41,34,13],当 q=5、s=2、t=5 时,i=1∑qbi+i=s∑tbi=23+49=72。
在第三个测试用例中,仅存在一个非空的连续子序列 [74]。当 q=1、s=1、t=1 时,i=1∑qbi+i=s∑tbi=148。
输入解题思路,AI测评打分。不知道怎么写?