?
以下记
考虑 DP:如果
如果
该 DP 可以前缀和优化。
如果
如果
:::success[code]
namespace DZ1000 {
typedef long long ll;
constexpr ll N = 1e5 + 10, P = 998244353;
ll t, n, ans;
array<ll, N> s, dp;
ll qpow(ll a, ll b) {
ll res = 1;
for(; b; b >>= 1, a = a * a % P) {
if(b & 1) {
res = res * a % P;
}
}
return res;
}
ll calc0() {
ll cnt = 0;
for(ll i = 1, j = 0; i <= n; i++) {
if(s[i] == s[j]) {
cnt++, j = i;
}
}
return qpow(2, cnt - 1);
}
ll calc(ll x) {
if(s[n] / x > n) {
return 0;
}
if(s[n] == x) {
return 1;
}
dp.fill(0);
dp[0] = 1;
for(ll i = 1; i < n; i++) {
if((s[i] == 0) || ((s[i] > 0) ^ (x > 0)) || (s[i] % x) || (s[i] / x > n)) {
continue;
}
dp[s[i] / x] = (dp[s[i] / x] + dp[s[i] / x - 1]) % P;
}
return dp[s[n] / x - 1];
}
void main() {
cin >> n;
for(ll i = 1; i <= n; i++) {
cin >> s[i];
s[i] += s[i - 1];
}
if(s[n] == 0) {
cout << calc0() << '\n';
return;
}
if(s[n] < 0) {
for(ll i = 1; i <= n; i++) {
s[i] = -s[i];
}
}
ans = 0;
for(ll k = 1; k * k <= s[n]; k++) {
if(s[n] % k == 0) {
ans = (ans + calc(k) + calc(s[n] / k)) % P;
}
}
cout << ans << '\n';
}
}
:::