Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
35600 | 林芳菲 | 【J】T4 | C++ | 通过 | 100 | 229 MS | 1528 KB | 1006 | 2024-12-13 20:42:32 |
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int MOD = 998244353; int sub, t, n; int a[100010]; char b[100010]; long long f[100010]; int main() { // freopen("calc.in", "r", stdin); // freopen("calc.out", "w", stdout); scanf("%d %d", &sub, &t); while (t--) { scanf("%d", &n); for (int i = 1; i < n; i++) scanf("%d %c", &a[i], &b[i]); scanf("%d", &a[n]); memset(f, 0, sizeof(f)); f[1] = a[1]; int last = 0; long long mul1, mul2, ans; mul1 = mul2 = ans = a[1]; for (int i = 2; i <= n; i++) { if (b[i - 1] == '+') { mul1 = 0; mul2 = 1; last = i - 1; } mul1 = (mul1 * a[i] % MOD + a[i]) % MOD; mul2 = mul2 * a[i] % MOD; f[i] = (f[last] + mul2 * last % MOD + mul1) % MOD; ans = (ans + f[i]) % MOD; } printf("%lld\n", ans); } // fclose(stdin); // fclose(stdout); return 0; }