CF2228E1.Amanojaku and Sequence (Easy Version)
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tinkerbell of Inequality
— Taboo Japan Disentanglement
This is the easy version of the problem. The difference between the versions is that in this version, q=1 and op=2. You can hack only if you solved all versions of this problem.
For a sequence s, let ∣s∣ denote its length.
For a non-negative integer sequence c, define f(c) as the sum of the squares of its prefix sums: $$ f(c)=\sum_{i=1}{|c|}\left(\sum_{j=1}{i} c_j\right)^2. $$
Now define g(b,m) as follows.
Let b be an integer sequence such that bi≥−1 for every i, and let m be a non-negative integer. A non-negative integer sequence c is called valid for (b,m) if all of the following conditions hold:
- ∣c∣=∣b∣;
- ∑i=1∣c∣ci=m;
- for every 1≤i≤∣b∣, if bi≥0, then ci=bi; otherwise, if bi=−1, then ci may be any non-negative integer.
The value g(b,m) is defined as the sum of f(c) over all valid sequences c for (b,m). If there is no such sequence, then g(b,m)=0.
You are given an array a of length n, where ai≥−1, and q queries of the following one type:
- Given three integers l, r, and m, compute g([al,al+1,…,ar],m) modulo 998244353, where [al,al+1,…,ar] denotes the subarray∗ of a from position l to position r.
∗An array a is a subarray of an array b if a can be obtained from b by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
不等式的 tinkerbelle
——禁忌日本解缠问题
本题为简单版本。两个版本的区别在于:在本版本中,q=1 且 op=2。仅当您已解决本题所有版本后,才可进行 hack。
对于一个序列 s,记 ∣s∣ 表示其长度。
对于一个非负整数序列 c,定义 f(c) 为其前缀和的平方之和:
f(c)=i=1∑∣c∣(j=1∑icj)2.
现定义 g(b,m) 如下:
设 b 是一个整数序列,满足对每个 i 都有 bi≥−1;设 m 是一个非负整数。若一个非负整数序列 c 满足以下全部条件,则称其对 (b,m) 有效:
- ∣c∣=∣b∣;
- ∑i=1∣c∣ci=m;
- 对每个 1≤i≤∣b∣,若 bi≥0,则 ci=bi;否则(即 bi=−1),ci 可取任意非负整数。
定义 g(b,m) 为所有对 (b,m) 有效的序列 c 对应的 f(c) 值之和。若不存在这样的序列,则 g(b,m)=0。
给定一个长度为 n 的数组 a,其中每个 ai≥−1,以及 q 个如下类型的查询:
- 给定三个整数 l、r 和 m,计算 g([al,al+1,…,ar],m) 对 998244353 取模的结果,其中 [al,al+1,…,ar] 表示数组 a 从位置 l 到位置 r 的子数组∗。
∗ 若数组 a 可通过从数组 b 的开头删除若干(可能为零或全部)元素、再从结尾删除若干(可能为零或全部)元素而得到,则称 a 是 b 的一个子数组。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
For each test case, the first line contains two integers n and q (1≤n≤3⋅105, q=1).
The second line contains n integers a1,a2,…,an (−1≤ai≤106).
Then q lines follow. Each line describes a query in the following format. The first integer op is 2.
- 2lrm: compute g([al,al+1,…,ar],m) modulo 998244353 (1≤l≤r≤n, 0≤m≤106).
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含测试用例数量 t(1≤t≤104)。随后是各测试用例的描述。
对于每个测试用例,第一行包含两个整数 n 和 q(1≤n≤3⋅105,q=1)。
第二行包含 n 个整数 a1,a2,…,an(−1≤ai≤106)。
接下来是 q 行,每行描述一个查询,格式如下。第一个整数 op 恒为 2。
- 2lrm:计算 g([al,al+1,…,ar],m) 对 998244353 取模的结果(其中 1≤l≤r≤n,0≤m≤106)。
保证所有测试用例的 n 之和不超过 3⋅105。
输出格式
For each test case, for every query of the second type, output the value of g([al,al+1,…,ar],m) modulo 998244353 on a line.
对于每个测试用例,对每一个第二类查询,在一行中输出 g([al,al+1,…,ar],m) 对 998244353 取模的值。
输入输出样例
输入#1
10 5 1 4 -1 7 6 -1 2 2 2 2 5 1 4 -1 8 6 -1 2 3 3 0 5 1 4 -1 8 6 -1 2 4 5 8 5 1 4 -1 8 6 7 2 3 5 21 5 1 4 -1 8 6 7 2 3 5 22 4 1 -1 -1 -1 -1 2 1 1 4 4 1 -1 -1 -1 -1 2 1 2 5 4 1 -1 -1 -1 -1 2 1 3 6 4 1 -1 -1 -1 -1 2 1 4 7 4 1 -1 -1 3 -1 2 1 4 5
输出#1
4 0 100 701 0 16 205 1736 12180 286
说明/提示
In the first test case:
l=r=2 and m=2. The subarray is [a2]=[−1], so the only valid sequence is c=[2]. Thus, the answer is 22=4.
In the third test case:
l=4, r=5, and m=8. The subarray is [a4,a5]=[6,−1]. Since c1 is fixed at 6 and c1+c2=m, we obtain c=[6,2]. The prefix sums are 6 and 8, giving $$ f(c)=62+(6+2)2=36+64=100. $$
In the seventh test case:
The subarray is [a1,a2]=[−1,−1]. All valid sequences satisfy c1+c2=5 with c1,c2≥0, namely [0,5],[1,4],…,[5,0]. Summing f(c) over all such sequences yields 205.
在第一个测试用例中:
l=r=2 且 m=2。子数组为 [a2]=[−1],因此唯一合法的序列是 c=[2]。故答案为 22=4。
在第三个测试用例中:
l=4,r=5,且 m=8。子数组为 [a4,a5]=[6,−1]。由于 c1 固定为 6,且 c1+c2=m,可得 c=[6,2]。其前缀和依次为 6 和 8,因此
f(c)=62+(6+2)2=36+64=100.
在第七个测试用例中:
子数组为 [a1,a2]=[−1,−1]。所有合法序列满足 c1+c2=5 且 c1,c2≥0,即 [0,5],[1,4],…,[5,0]。对所有此类序列求 f(c) 的和,结果为 205。
输入解题思路,AI测评打分。不知道怎么写?