提交时间:2024-09-08 15:14:38

运行 ID: 32328

//WHY ALWAYS MATHHHHHHHHHHHHHHHHHHHHHHHHH //100pts O(max(sqrt(k), log(k) * (n + m) * log(n + m))) #include <bits/stdc++.h> #define int long long #define mkp make_pair #define pii pair<int,int> using namespace std; const int mod = 998244353; int n, m, k, a[100005], b[100005], f[100005], sa[100005], sb[100005]; int az[100005], af[100005], bz[100005], bf[100005]; signed main() { //freopen("rain.in", "r", stdin); //freopen("rain.out", "w", stdout); scanf("%lld %lld %lld", &n, &m, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); sa[i] = sa[i - 1] + a[i]; az[i] = ((az[i - 1] + 1) * (1 - a[i])) % mod; } for (int i = 1; i <= m; i++) { scanf("%lld", &b[i]); sb[i] = sb[i - 1] + b[i]; bz[i] = ((bz[i - 1] + 1) * (1 - b[i])) % mod; } for (int i = n; i >= 1; i--) af[i] = ((af[i + 1] + 1) * (1 - a[i])) % mod; for (int i = m; i >= 1; i--) bf[i] = ((bf[i + 1] + 1) * (1 - b[i])) % mod; // for (int i = 1; i <= m; i++) // { // printf("%lld ", bz[i]); // } // puts(""); // for (int i = 1; i <= m; i++) // { // printf("%lld ", bf[i]); // } // puts(""); int rk = k; int ans = 0; for (int i = 1; i * i <= k; i++) { if (k % i != 0) continue; int res1 = 0, res2 = 0, r1 = 0, r2 = 0, pos = lower_bound(sb + 1, sb + m + 1, sb[1] + i - 1) - sb; int ps1 = lower_bound(sb + 1, sb + m + 1, sb[1] + (k / i) - 1) - sb; for (int j = 1; j <= m; j++) { if (b[j] == 0) { continue; } int cc = 0, cd = 0; if (pos != m + 1) { cc = 1; if (j != 1 && b[j - 1] == 0) cc *= (bz[j - 1] + 1); if (pos != m && b[pos + 1] == 0) cc *= (bf[pos + 1] + 1); res1 += cc; res1 %= mod; // printf("[%lld, %lld] + %lld\n", j, pos, cc); } if (ps1 != m + 1) { cd = 1; if (j != 1 && b[j - 1] == 0) cd *= (bz[j - 1] + 1); if (ps1 != m && b[ps1 + 1] == 0) cd *= (bf[ps1 + 1] + 1); res2 += cd; res2 %= mod; } if (cc == 0 && cd == 0) break; pos++, ps1++; while (b[ps1] == 0 && ps1 <= m) ps1++; while (b[pos] == 0 && pos <= m) pos++; } pos = lower_bound(sa + 1, sa + n + 1, sa[1] + i - 1) - sa; ps1 = lower_bound(sa + 1, sa + n + 1, sa[1] + (k / i) - 1) - sa; for (int j = 1; j <= n; j++) { if (a[j] == 0) continue; int cc = 0, cd = 0; if (pos != n + 1) { cc = 1; if (j != 1 && a[j - 1] == 0) cc *= (az[j - 1] + 1); if (pos != n && a[pos + 1] == 0) cc *= (af[pos + 1] + 1); r1 += cc; r1 %= mod; } if (ps1 != n + 1) { cd = 1; if (j != 1 && a[j - 1] == 0) cd *= (az[j - 1] + 1); if (ps1 != n && a[ps1 + 1] == 0) cd *= (af[ps1 + 1] + 1); r2 += cd; r2 %= mod; } pos++, ps1++; while (b[ps1] == 0 && ps1 <= n) ps1++; while (b[pos] == 0 && pos <= n) pos++; } // printf("%lldx%lld:%lld*%lld=%lld\n", i, k / i, res1, r2, res1 * r2); // printf("%lldx%lld:%lld*%lld=%lld\n", k / i, i, res2, r1, res2 * r1); if (i * i != k) { ans = (ans + (res1 * r2 + res2 * r1) % mod) % mod; } else ans = (ans + (res1 * r1)) % mod; } printf("%lld", ans); fclose(stdout); }