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=1q=1 and op=2\mathrm{op}=2. You can hack only if you solved all versions of this problem.

For a sequence ss, let ∣s∣|s| denote its length.

For a non-negative integer sequence cc, define f(c)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)g(b,m) as follows.

Let bb be an integer sequence such that bi≥−1b_i\ge -1 for every ii, and let mm be a non-negative integer. A non-negative integer sequence cc is called valid for (b,m)(b,m) if all of the following conditions hold:

  • ∣c∣=∣b∣|c|=|b|;
  • ∑i=1∣c∣ci=m\sum_{i=1}^{|c|} c_i=m;
  • for every 1≤i≤∣b∣1\le i\le |b|, if bi≥0b_i\ge 0, then ci=bic_i=b_i; otherwise, if bi=−1b_i=-1, then cic_i may be any non-negative integer.

The value g(b,m)g(b,m) is defined as the sum of f(c)f(c) over all valid sequences cc for (b,m)(b,m). If there is no such sequence, then g(b,m)=0g(b,m)=0.

You are given an array aa of length nn, where ai≥−1a_i\ge -1, and qq queries of the following one type:

  • Given three integers ll, rr, and mm, compute g([al,al+1,…,ar],m)g([a_l,a_{l+1},\ldots,a_r],m) modulo 998 244 353998\,244\,353, where [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r] denotes the subarray∗^{\text{∗}} of aa from position ll to position rr.

∗^{\text{∗}}An array aa is a subarray of an array bb if aa can be obtained from bb 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=1q=1 且 op=2\mathrm{op}=2。仅当您已解决本题所有版本后,才可进行 hack。

对于一个序列 ss,记 ∣s∣|s| 表示其长度。

对于一个非负整数序列 cc,定义 f(c)f(c) 为其前缀和的平方之和:

f(c)=∑i=1∣c∣(∑j=1icj)2.f(c)=\sum_{i=1}^{|c|}\left(\sum_{j=1}^{i} c_j\right)^2.

现定义 g(b,m)g(b,m) 如下:

设 bb 是一个整数序列,满足对每个 ii 都有 bi≥−1b_i \ge -1;设 mm 是一个非负整数。若一个非负整数序列 cc 满足以下全部条件,则称其对 (b,m)(b,m) 有效:

  • ∣c∣=∣b∣|c|=|b|;
  • ∑i=1∣c∣ci=m\sum_{i=1}^{|c|} c_i=m;
  • 对每个 1≤i≤∣b∣1\le i\le |b|,若 bi≥0b_i\ge 0,则 ci=bic_i=b_i;否则(即 bi=−1b_i=-1),cic_i 可取任意非负整数。

定义 g(b,m)g(b,m) 为所有对 (b,m)(b,m) 有效的序列 cc 对应的 f(c)f(c) 值之和。若不存在这样的序列,则 g(b,m)=0g(b,m)=0。

给定一个长度为 nn 的数组 aa,其中每个 ai≥−1a_i \ge -1,以及 qq 个如下类型的查询:

  • 给定三个整数 ll、rr 和 mm,计算 g([al,al+1,…,ar],m)g([a_l,a_{l+1},\ldots,a_r],m) 对 998 244 353998\,244\,353 取模的结果,其中 [al,al+1,…,ar][a_l,a_{l+1},\ldots,a_r] 表示数组 aa 从位置 ll 到位置 rr 的子数组∗^{\text{∗}}。

∗^{\text{∗}} 若数组 aa 可通过从数组 bb 的开头删除若干(可能为零或全部)元素、再从结尾删除若干(可能为零或全部)元素而得到,则称 aa 是 bb 的一个子数组。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

For each test case, the first line contains two integers nn and qq (1≤n≤3⋅1051\leq n\leq 3\cdot 10^5, q=1q=1).

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

Then qq lines follow. Each line describes a query in the following format. The first integer op\textrm{op} is 22.

  • 2 l r m2\,l\,r\,m: compute g([al,al+1,…,ar],m)g([a_l,a_{l+1},\ldots,a_r],m) modulo 998 244 353998\,244\,353 (1≤l≤r≤n1\leq l\leq r\leq n, 0≤m≤1060\leq m\leq 10^6).

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

对于每个测试用例,第一行包含两个整数 nn 和 qq(1≤n≤3⋅1051\leq n\leq 3\cdot 10^5,q=1q=1)。

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

接下来是 qq 行,每行描述一个查询,格式如下。第一个整数 op\textrm{op} 恒为 22。

  • 2 l r m2\,l\,r\,m:计算 g([al,al+1,…,ar],m)g([a_l,a_{l+1},\ldots,a_r],m) 对 998 244 353998\,244\,353 取模的结果(其中 1≤l≤r≤n1\leq l\leq r\leq n,0≤m≤1060\leq m\leq 10^6)。

保证所有测试用例的 nn 之和不超过 3⋅1053\cdot 10^5。

输出格式

For each test case, for every query of the second type, output the value of g([al,al+1,…,ar],m)g([a_l,a_{l+1},\ldots,a_r],m) modulo 998 244 353998\,244\,353 on a line.

对于每个测试用例,对每一个第二类查询,在一行中输出 g([al,al+1,…,ar],m)g([a_l,a_{l+1},\ldots,a_r],m) 对 998 244 353998\,244\,353 取模的值。

输入输出样例

  • 输入#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=2l=r=2 and m=2m=2. The subarray is [a2]=[−1][a_2]=[-1], so the only valid sequence is c=[2]c=[2]. Thus, the answer is 22=42^2=4.

In the third test case:

l=4l=4, r=5r=5, and m=8m=8. The subarray is [a4,a5]=[6,−1][a_4,a_5]=[6,-1]. Since c1c_1 is fixed at 66 and c1+c2=mc_1+c_2=m, we obtain c=[6,2]c=[6,2]. The prefix sums are 66 and 88, giving $$ f(c)=62+(6+2)2=36+64=100. $$

In the seventh test case:

The subarray is [a1,a2]=[−1,−1][a_1,a_2]=[-1,-1]. All valid sequences satisfy c1+c2=5c_1+c_2=5 with c1,c2≥0c_1,c_2\ge 0, namely [0,5],[1,4],…,[5,0][0,5],[1,4],\ldots,[5,0]. Summing f(c)f(c) over all such sequences yields 205205.

在第一个测试用例中:

l=r=2l=r=2 且 m=2m=2。子数组为 [a2]=[−1][a_2]=[-1],因此唯一合法的序列是 c=[2]c=[2]。故答案为 22=42^2=4。

在第三个测试用例中:

l=4l=4,r=5r=5,且 m=8m=8。子数组为 [a4,a5]=[6,−1][a_4,a_5]=[6,-1]。由于 c1c_1 固定为 66,且 c1+c2=mc_1+c_2=m,可得 c=[6,2]c=[6,2]。其前缀和依次为 66 和 88,因此

f(c)=62+(6+2)2=36+64=100.f(c)=6^2+(6+2)^2=36+64=100.

在第七个测试用例中:

子数组为 [a1,a2]=[−1,−1][a_1,a_2]=[-1,-1]。所有合法序列满足 c1+c2=5c_1+c_2=5 且 c1,c2≥0c_1,c_2\ge 0,即 [0,5],[1,4],…,[5,0][0,5],[1,4],\ldots,[5,0]。对所有此类序列求 f(c)f(c) 的和,结果为 205205。

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

首页