| Codeforces Round 1098 (Div. 2) |
|---|
| Finished |
This is the easy version of the problem. The difference between the versions is that in this version, $$$q=1$$$ and $$$\mathrm{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 $$$b_i\ge -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:
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 $$$a_i\ge -1$$$, and $$$q$$$ queries of the following one type:
$$$^{\text{∗}}$$$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.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
For each test case, the first line contains two integers $$$n$$$ and $$$q$$$ ($$$1\leq n\leq 3\cdot 10^5$$$, $$$q=1$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-1\leq a_i\leq 10^6$$$).
Then $$$q$$$ lines follow. Each line describes a query in the following format. The first integer $$$\textrm{op}$$$ is $$$2$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot 10^5$$$.
For each test case, for every query of the second type, output the value of $$$g([a_l,a_{l+1},\ldots,a_r],m)$$$ modulo $$$998\,244\,353$$$ on a line.
105 14 -1 7 6 -12 2 2 25 14 -1 8 6 -12 3 3 05 14 -1 8 6 -12 4 5 85 14 -1 8 6 72 3 5 215 14 -1 8 6 72 3 5 224 1-1 -1 -1 -12 1 1 44 1-1 -1 -1 -12 1 2 54 1-1 -1 -1 -12 1 3 64 1-1 -1 -1 -12 1 4 74 1-1 -1 3 -12 1 4 5
40100701016205173612180286
In the first test case:
$$$l=r=2$$$ and $$$m=2$$$. The subarray is $$$[a_2]=[-1]$$$, so the only valid sequence is $$$c=[2]$$$. Thus, the answer is $$$2^2=4$$$.
In the third test case:
$$$l=4$$$, $$$r=5$$$, and $$$m=8$$$. The subarray is $$$[a_4,a_5]=[6,-1]$$$. Since $$$c_1$$$ is fixed at $$$6$$$ and $$$c_1+c_2=m$$$, we obtain $$$c=[6,2]$$$. The prefix sums are $$$6$$$ and $$$8$$$, giving $$$$$$ f(c)=6^2+(6+2)^2=36+64=100. $$$$$$
In the seventh test case:
The subarray is $$$[a_1,a_2]=[-1,-1]$$$. All valid sequences satisfy $$$c_1+c_2=5$$$ with $$$c_1,c_2\ge 0$$$, namely $$$[0,5],[1,4],\ldots,[5,0]$$$. Summing $$$f(c)$$$ over all such sequences yields $$$205$$$.
| Name |
|---|


