Codeforces Round 1008 (Div. 2)
G
Another Folding Strip
Codeforces
未评级
原题
← F→
翻译中…

For an array $b$ of length $m$, define $f(b)$ as follows.

翻译中…

Consider a $1 \times m$ strip, where all cells initially have darkness $0$. You want to transform it into a strip where the color at the $i$-th position has darkness $b_i$. You can perform the following operation, which consists of two steps:

翻译中…
  1. Fold the paper at any line between two cells. You may fold as many times as you like, or choose not to fold at all.
  2. Choose one position to drop the black dye. The dye permeates from the top and flows down to the bottom, increasing the darkness of all cells in its path by $1$. After dropping the dye, you unfold the strip.
翻译中…

Let $f(b)$ be the minimum number of operations required to achieve the desired configuration. It can be proven that the goal can always be achieved in a finite number of operations.

翻译中…

You are given an array $a$ of length $n$. Evaluate

翻译中…

$$\sum_{l=1}^n\sum_{r=l}^n f(a_l a_{l+1} \ldots a_r)$$

翻译中…

modulo $998\,244\,353$.

翻译中…

Input

翻译中…

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.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of the array $a$.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^9$) — denoting the array $a$.

翻译中…

It is guaranteed that the sum of all values of $n$ across all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the required sum modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case,

翻译中…
  • $f(a_1)=f(\mathtt{0})=0$
  • $f(a_1a_2)=f(\mathtt{01})=1$
  • $f(a_1a_2a_3)=f(\mathtt{010})=1$
  • $f(a_2)=f(\mathtt{1})=1$
  • $f(a_2a_3)=f(\mathtt{10})=1$
  • $f(a_3)=f(\mathtt{0})=0$
翻译中…

This sums up to $0+1+1+1+1+0 = 4$

翻译中…

In the second test case, $f(a_1a_2a_3a_4a_5a_6) = 2$. Here's one possible sequence of operations.

翻译中…

image

翻译中…

样例

Input #1
4
3
0 1 0
6
1 0 0 1 2 1
5
2 1 2 4 3
12
76 55 12 32 11 45 9 63 88 83 32 6
Output #1
4
28
47
7001
InputCopy OutputCopy
题目信息
题号
2078G
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。