9584: Another Day of Sun

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:4 通过:1

题目描述

'Cause morning rolls around, and it's another day of sun!

But as a sleep addict, Sean spends lots of hours sleeping, and thus, he can't even remember which day it is when he wakes up.

So starting from someday, he started taking notes: when he wakes up, he writes a number about whether there's sunlight outside. If there is, he will write a 1 on it; otherwise, he will write a 0 . And after taking notes, without enough time for sunlight to fade or for moonlight to dim, he falls asleep again. We assume that every time Sean wakes up, he sees either the sunlight or the moonlight, but not both.

So the notes actually form an array of length n : [a1,a2,,an] (1in,0ai1) , where ai represents the i-th number Sean wrote.

However, as time goes on, some numbers written become ambiguous and are just impossible to identify, and you can't really tell whether it is a 1 or a 0 . So if there are k numbers that you can't identify, there can be 2k different arrays.

For each array, you can calculate the minimum number of days on which Sean sees the sunlight at least once that is consistent with the notes the array represents. If you add the results of different arrays together, what will you get? As the answer can get quite enormous, output it modulo 998 244 353 .

Note that we only care about the minimum number of days when the notes with number 1 are taken.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases T (1T104) .
Each test case consists of two lines.
The first line contains one integer n (2n5×105), the number of notes.
The second line contains n integers a1,a2,,an (1ai1), each number written on the note. The number is unknown if and only if ai=1.
It is guaranteed that n over all test cases in one test will not exceed 5×105.

输出格式

For each test case, output 1 integer: the sum of results modulo 998 244 353 .

输入样例 复制

3
3
1 0 1
3
0 0 0
3
1 -1 1

输出样例 复制

2
0
3

数据范围与提示

In the first test case, when Sean takes the first note and the third note, the sun he has seen must have been of 2 different days.
In the second test case, Sean never sees the sun, so the answer is 0.

In the third test case, the array can be [1,1,1] or [1,0,1]. If the array is [1,1,1], the notes can be taken in the same day, so Sean could have seen the daylight of the same day, and the result is 1. If the array is [1,0,1], the first and third notes must have been taken in different days, so there are at least 2 days of sun that Sean has seen. So the answer is 1+2=3.