Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
32324 沈仲恩 【S】T1 C++ 通过 100 762 MS 6520 KB 4178 2024-09-08 15:12:20

Tests(20/20):


//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; int pos = 1, ps = 1; for (int j = 1; j <= m; j++) { if (b[j] == 0) { continue; } pos = lower_bound(sb + pos, sb + m + 1, sb[j] + i - 1) - sb; int cc = 0, cd = 0; if (pos != m + 1) { cc = 1; if (j != 1 && b[j - 1] == 0) cc *= (bz[j - 1] + 1); cc %= mod; if (pos != m && b[pos + 1] == 0) cc *= (bf[pos + 1] + 1); cc %= mod; res1 += cc; res1 %= mod; // printf("[%lld, %lld] + %lld\n", j, pos, cc); } ps = lower_bound(sb + ps, sb + m + 1, sb[j] + (k / i) - 1) - sb; if (ps != m + 1) { cd = 1; if (j != 1 && b[j - 1] == 0) cd *= (bz[j - 1] + 1); cd %= mod; if (ps != m && b[ps + 1] == 0) cd *= (bf[ps + 1] + 1); cd %= mod; res2 += cd; res2 %= mod; } if (cc == 0 && cd == 0) break; } pos = 1, ps = 1; for (int j = 1; j <= n; j++) { if (a[j] == 0) continue; pos = lower_bound(sa + pos, sa + n + 1, sa[j] + i - 1) - sa; int cc = 0, cd = 0; if (pos != n + 1) { cc = 1; if (j != 1 && a[j - 1] == 0) cc *= (az[j - 1] + 1); cc %= mod; if (pos != n && a[pos + 1] == 0) cc *= (af[pos + 1] + 1); cc %= mod; r1 += cc; r1 %= mod; } ps = lower_bound(sa + ps, sa + n + 1, sa[j] + (k / i) - 1) - sa; if (ps != n + 1) { cd = 1; if (j != 1 && a[j - 1] == 0) cd *= (az[j - 1] + 1); cd %= mod; if (ps != n && a[ps + 1] == 0) cd *= (af[ps + 1] + 1); cd %= mod; r2 += cd; r2 %= mod; } } // 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 % mod + res2 * r1 % mod) % mod) % mod; } else ans = (ans + (res1 * r1) % mod) % mod; } printf("%lld", ans); fclose(stdout); }


测评信息: