1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <bits/stdc++.h> using namespace std; template <typename t> void read(t &x) { char ch = getchar(); x = 0; t f = 1; while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : f), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= f; }
#define wi(n) printf("%d ", n) #define wl(n) printf("%lld ", n) #define P puts(" ") typedef long long ll; #define MOD 1000000007 #define mp(a, b) make_pair(a, b) #define N 20005 #define rep(i, j, n) for (int i = j; i <= n; i++) #define red(i, n, j) for (int i = n; i >= j; i--) #define fil(a, n) rep(i, 0, n, ) read(a[i])
const int N = 4e4 + 100; int a[N], b[N]; vector<pair<int, int>> node; void init(int k) { for (int i = 1; i * i <= k; i++) { if (k % i == 0) { node.push_back(make_pair(i, k / i)); if (i != k / i) node.push_back(make_pair(k / i, i)); } } } unordered_map<int, int> A, B; void solve(int a[], int n, unordered_map<int, int> &mp) { int pos = 1, cnt = 0; while (pos <= n) { while (a[pos]) { pos++; cnt++; } if (cnt) { mp[cnt]++; cnt = 0; } pos++; } }
int main() { int n, m, k; read(n), read(m), read(k); init(k); rep(i, 1, n + 1) read(a[i]); rep(i, 1, m + 1) read(b[i]); solve(a, n, A); solve(b, m, B); LL ans = 0; rep(k, 0, node.size()) { int x = node[k].first, y = node[k].second; LL xx = 0, yy = 0; for (auto it : A) if (it.first >= x) xx += it.second * (it.first - x + 1); for (auto it : B) if (it.first >= y) yy += it.second * (it.first - y + 1); ans += xx * yy; } wi(ans), P; return 0; }
|