Codeforces Round 983 (Div. 2)
F
Peanuts
Codeforces
2700
原题
← E→
翻译中…

Having the magical beanstalk, Jack has been gathering a lot of peanuts lately. Eventually, he has obtained $n$ pockets of peanuts, conveniently numbered $1$ to $n$ from left to right. The $i$-th pocket has $a_i$ peanuts.

翻译中…

Jack and his childhood friend Alice decide to play a game around the peanuts. First, Alice divides the pockets into some boxes; each box will have a non-zero number of consecutive pockets, and each pocket will, obviously, belong to exactly one box. At the same time, Alice does not change the order of the boxes, that is, the boxes are numbered in ascending order of the indices of the pockets in them.

翻译中…

After that, Alice and Jack will take turns alternately, with Alice going first.

翻译中…

At each turn, the current player will remove a positive number of peanuts from exactly one pocket which belongs to the leftmost non-empty box (i.e., the leftmost box containing at least one non-empty pocket). In other words, if we number the boxes from left to right, then each player can only pick peanuts from the pocket in the $j$-th box ($j \ge 2$) only if the $(j - 1)$-th box has no peanuts left. The player who cannot make a valid move loses.

翻译中…

Alice is sure she will win since she has the advantage of dividing the pockets into boxes herself. Thus, she wanted to know how many ways there are for her to divide the peanuts into boxes at the start of the game so that she will win, assuming both players play optimally. Can you help her with the calculation?

翻译中…

As the result can be very large, output it modulo $998\,244\,353$.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^6$) — the number of pockets.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the number of peanuts in each pocket.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of ways for Alice to divide the pockets into boxes at the start of the game to guarantee her win, assuming both players play optimally, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, the only way for Alice to win is to divide the pockets into two boxes as follows: $([1, 2], [3])$ (the first box contains the first two pockets and the second box contains the third pocket). Alice wins by taking both peanuts from the second pocket, leaving Jack with $([1], [3])$. Jack is forced to take the only peanut left in the first box, which allows Alice to take the remaining ones in the second box.

翻译中…

In the second test case, the winning divisions for Alice are $([1], [2, 3, 1])$, $([1, 2, 3, 1])$, $([1, 2], [3], [1])$, and $([1, 2], [3, 1])$.

翻译中…

In the third test case, Alice always wins no matter how she divides the pockets into boxes.

翻译中…

In the fourth test case, Alice always loses no matter how she divides the pockets into boxes.

翻译中…

样例

Input #1
5
3
1 2 3
4
1 2 3 1
5
1 1 1 1 1
2
1 1
10
1 2 3 4 5 6 7 8 9 10
Output #1
1
4
16
0
205
InputCopy OutputCopy
题目信息
题号
2032F
时间限制
4 s
内存限制
256 MB
标签
组合数学
动态规划
博弈论
数学

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