diff --git a/LibreOJ/3096/3096.cpp b/LibreOJ/3096/3096.cpp new file mode 100644 index 00000000..2b03ccf9 --- /dev/null +++ b/LibreOJ/3096/3096.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e6 + 5; + +int p, q, n, m, a[N], b[N], len, c[N], cnt, d[N], w[N], pos[N]; +long long t, ans; +std::vector g[N], s[N]; + +int dfs(int u, int c) { + if (::c[u]) return 0; + + ::c[u] = c; + g[c].emplace_back(u); + return d[u] + dfs((u + p) % q, c); +} + +int calc(int l, int x) { + return s[c[x]][pos[x] + l] - s[c[x]][pos[x]]; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> p >> q >> n >> m >> t; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int i = 1; i <= m; i++) { + cin >> b[i]; + } + + if (p > q) { + std::swap(p, q); + std::swap(n, m); + std::swap(a, b); + } + + len = q / std::__gcd(p, q); + + for (int i = 1; i <= m; i++) { + d[b[i]] = 1; + } + + for (int i = 0; i < q; i++) { + if (!c[i]) { + cnt++; + w[cnt] = dfs(i, cnt); + } + } + + for (int i = 1; i <= cnt; i++) { + for (int j = 0; j < g[i].size(); j++) { + pos[g[i][j]] = j; + } + + s[i] = g[i]; + + for (int j = 0; j < g[i].size() - 1; j++) { + s[i].emplace_back(g[i][j]); + } + + std::transform(s[i].begin(), s[i].end(), s[i].begin(), [&](int x) -> int { return d[x]; }); + std::partial_sum(s[i].begin(), s[i].end(), s[i].begin()); + } + + for (int i = 1; i <= n; i++) { + long long x = (t - 1 - a[i]) / p; + + ans += x / len * w[c[a[i]]]; + ans += static_cast(calc(x % len, a[i])) + d[a[i]]; + } + + cout << ans << endl; + + return 0; +} diff --git a/LibreOJ/3096/data/01 b/LibreOJ/3096/data/01 new file mode 100644 index 00000000..8f8c15e4 --- /dev/null +++ b/LibreOJ/3096/data/01 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0b7a52acbcd5a3bdefc37c12fb89aa488f6e8e793bc7f201a054e80c44b3352 +size 79998 diff --git a/LibreOJ/3096/data/01.a b/LibreOJ/3096/data/01.a new file mode 100644 index 00000000..a30924cb --- /dev/null +++ b/LibreOJ/3096/data/01.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00fe8277291a0c7b5a5c7c4bf8b855eff9f465d534cb5da71dd59166b1340ff6 +size 6 diff --git a/LibreOJ/3096/data/02 b/LibreOJ/3096/data/02 new file mode 100644 index 00000000..5b3a34d8 --- /dev/null +++ b/LibreOJ/3096/data/02 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1cf21072e203e406df417cdaff49e6e14fd4501e6c693e6e25ac08c7289b1c9b +size 5992 diff --git a/LibreOJ/3096/data/02.a b/LibreOJ/3096/data/02.a new file mode 100644 index 00000000..c8bb95c8 --- /dev/null +++ b/LibreOJ/3096/data/02.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4b5b7996d9c855b3da21636ad37ff7c2fa559c59462f937afbee2bd67c4e3f1 +size 18 diff --git a/LibreOJ/3096/data/03 b/LibreOJ/3096/data/03 new file mode 100644 index 00000000..7efc897b --- /dev/null +++ b/LibreOJ/3096/data/03 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29be1900031fd46cc76f755d1f19970bd2324e9c3df15f365377e3f6215fd7f4 +size 3829 diff --git a/LibreOJ/3096/data/03.a b/LibreOJ/3096/data/03.a new file mode 100644 index 00000000..671d6304 --- /dev/null +++ b/LibreOJ/3096/data/03.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59dece07d996c94ae27cd3348f204ebfdf1731add22358e494ee5e093fcb6560 +size 18 diff --git a/LibreOJ/3096/data/04 b/LibreOJ/3096/data/04 new file mode 100644 index 00000000..a2d9623f --- /dev/null +++ b/LibreOJ/3096/data/04 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b76642e219437b35854ea7ffdae22ce1793182e26592ef15af3e35ce6c3ba758 +size 9634014 diff --git a/LibreOJ/3096/data/04.a b/LibreOJ/3096/data/04.a new file mode 100644 index 00000000..69f1a1a1 --- /dev/null +++ b/LibreOJ/3096/data/04.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39d96e94ccb8dcc0763984ff36495498d3fa8fa03c297abc42bb55c9896ee909 +size 18 diff --git a/LibreOJ/3096/data/05 b/LibreOJ/3096/data/05 new file mode 100644 index 00000000..f4dba0fd --- /dev/null +++ b/LibreOJ/3096/data/05 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b41be4fecc0f91ae83276fc19826a6d5ee6fb782efe73945c44d35ebf11022b5 +size 588815 diff --git a/LibreOJ/3096/data/05.a b/LibreOJ/3096/data/05.a new file mode 100644 index 00000000..46337276 --- /dev/null +++ b/LibreOJ/3096/data/05.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca66e2b351fe322348a7f8b5b0067ca230fa7e18cf121521da3595c91658c542 +size 18 diff --git a/LibreOJ/3096/data/06 b/LibreOJ/3096/data/06 new file mode 100644 index 00000000..b065479e --- /dev/null +++ b/LibreOJ/3096/data/06 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a72c3ed746cccc099fa8b6a7ddc50050ace39ea59829fa57d1c9b13d0192b457 +size 2361239 diff --git a/LibreOJ/3096/data/06.a b/LibreOJ/3096/data/06.a new file mode 100644 index 00000000..eaa0ecf2 --- /dev/null +++ b/LibreOJ/3096/data/06.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b63b913b7678831cc0ceb3d4ea442fddc64136a959b9c1d1cf48631710661d47 +size 18 diff --git a/LibreOJ/3096/data/07 b/LibreOJ/3096/data/07 new file mode 100644 index 00000000..efe6267b --- /dev/null +++ b/LibreOJ/3096/data/07 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e7b3c848642721fde06b03b76f4c2de4319a5247d6ddf966f25883b09f33648 +size 587072 diff --git a/LibreOJ/3096/data/07.a b/LibreOJ/3096/data/07.a new file mode 100644 index 00000000..8ef1bfb1 --- /dev/null +++ b/LibreOJ/3096/data/07.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d866d3c05710c27efa4161ce401934c95207bd97ffdc4fe0a65d80648a7abb3 +size 18 diff --git a/LibreOJ/3096/data/08 b/LibreOJ/3096/data/08 new file mode 100644 index 00000000..98d2d5db --- /dev/null +++ b/LibreOJ/3096/data/08 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3436e4eb85de3d633adcb1b1b4043ae83c285b239a8dd6fdd5a7842793dbe13 +size 6623261 diff --git a/LibreOJ/3096/data/08.a b/LibreOJ/3096/data/08.a new file mode 100644 index 00000000..059f1445 --- /dev/null +++ b/LibreOJ/3096/data/08.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b3aae591e2317a4b93296c5fce4eea6db82674c85eeace7b4e610fae0a404c7e +size 18 diff --git a/LibreOJ/3096/data/09 b/LibreOJ/3096/data/09 new file mode 100644 index 00000000..f176d40d --- /dev/null +++ b/LibreOJ/3096/data/09 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39ae04bb94c0cac3737f99995621dc7721a6ce48ddb44dc559dad0080b5d5cd9 +size 6891895 diff --git a/LibreOJ/3096/data/09.a b/LibreOJ/3096/data/09.a new file mode 100644 index 00000000..df269251 --- /dev/null +++ b/LibreOJ/3096/data/09.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04a9cee170196937eb9a66bc629e385c7364c134d20157031cdf4ca1b8d3244a +size 18 diff --git a/LibreOJ/3096/data/10 b/LibreOJ/3096/data/10 new file mode 100644 index 00000000..dcbefe12 --- /dev/null +++ b/LibreOJ/3096/data/10 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ea45eb419950539547f48401500adc3ef667149af5d538f2c40077d6b6d0457 +size 8618672 diff --git a/LibreOJ/3096/data/10.a b/LibreOJ/3096/data/10.a new file mode 100644 index 00000000..3dd99ac2 --- /dev/null +++ b/LibreOJ/3096/data/10.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16d19d7c506d4fb4e64b26f58c9d8f395916b2ff5b134cfbd24ffee71e3c5706 +size 18