注意点:
1:要的是x的最大值求余而不是求余后的最大值
2:对于sum的提前处理应该是 > 1而不是 sum != 0(只能过55,浪费时间)
3:因为第一点的缘故,后面只要提前处理了sum,遇到> 1的数直接相乘即可
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>
using namespace std;
using i64 = int64_t;
#define endl '\n'
#define int i64
const int maxn = 1e6 + 10;
const int mod = 998244353;
signed main()
{
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n;
int sum = 0;
while (sum <= 1 && n)
{
cin >> m;
sum += m;
n--;
}
sum %= mod;
while (n--)
{
cin >> m;
if (m == 0 || m == 1)
sum += m;
else
sum *= m;
sum %= mod;
}
cout << sum % mod << endl;
}
return 0;
}