diff --git a/Luogu/P4774/P4774.cpp b/Luogu/P4774/P4774.cpp new file mode 100644 index 00000000..adb9775c --- /dev/null +++ b/Luogu/P4774/P4774.cpp @@ -0,0 +1,97 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int t, n, m; +long long max; +std::tuple dragon[N]; +std::multiset set; + +long long exgcd(long long a, long long b, long long& x, long long& y) { + if (!b) { + x = 1, y = 0; + return a; + } + + long long g = exgcd(b, a % b, y, x); + y -= a / b * x; + return g; +} + +long long excrt() { + long long res = 0, lcm = 1; + + for (int i = 1; i <= n; i++) { + long long a = (__int128)(std::get<3>(dragon[i])) * lcm % std::get<1>(dragon[i]), + b = std::get<1>(dragon[i]), + c = (__int128)(std::get<0>(dragon[i]) - std::get<3>(dragon[i]) * res % b + b) % b, + x, y; + + long long g = exgcd(a, b, x, y); + x = (x % b + b) % b; + + if (c % g) return -1; + + res += (__int128)(c / g) * x % (b / g) * lcm % (lcm * (b / g)); + lcm *= b / g; + res %= lcm; + } + + if (res < max) res += ((max - res - 1) / lcm + 1) * lcm; + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> t; + + while (t--) { + max = 0; + set.clear(); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> std::get<0>(dragon[i]); + } + + for (int i = 1; i <= n; i++) { + cin >> std::get<1>(dragon[i]); + } + + for (int i = 1; i <= n; i++) { + cin >> std::get<2>(dragon[i]); + } + + for (int i = 1, x; i <= m; i++) { + cin >> x; + + set.insert(x); + } + + for (int i = 1; i <= n; i++) { + auto it = set.upper_bound(std::get<0>(dragon[i])); + + if (it != set.begin()) it--; + + std::get<3>(dragon[i]) = *it; + set.insert(std::get<2>(dragon[i])); + max = std::max(max, (std::get<0>(dragon[i]) - 1) / *it + 1); + + set.erase(it); + } + + cout << excrt() << endl; + } + + return 0; +} diff --git a/Luogu/P4774/data/P4774_1.in b/Luogu/P4774/data/P4774_1.in new file mode 100644 index 00000000..78e7ff70 --- /dev/null +++ b/Luogu/P4774/data/P4774_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2819cc854133f88bbfa7cfed783e9f737000809a53048374f07cbcb7eae6abd1 +size 4396035 diff --git a/Luogu/P4774/data/P4774_1.out b/Luogu/P4774/data/P4774_1.out new file mode 100644 index 00000000..91a2087a --- /dev/null +++ b/Luogu/P4774/data/P4774_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b74164f7c98d1e0aedd3c92e0330b8ba893d0692bbd62c5cde4b1bdcebaf4b09 +size 25 diff --git a/Luogu/P4774/data/P4774_10.in b/Luogu/P4774/data/P4774_10.in new file mode 100644 index 00000000..455643ac --- /dev/null +++ b/Luogu/P4774/data/P4774_10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9796497c8a3b1f6812a9c066ddd6ff32b9a245392b9a7e157f6bb059fde09cb4 +size 156 diff --git a/Luogu/P4774/data/P4774_10.out b/Luogu/P4774/data/P4774_10.out new file mode 100644 index 00000000..76d10690 --- /dev/null +++ b/Luogu/P4774/data/P4774_10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c84432cc71769da98e19524ef38036cbe996ce4c833d974dbdd54f62134b3f6 +size 44 diff --git a/Luogu/P4774/data/P4774_11.in b/Luogu/P4774/data/P4774_11.in new file mode 100644 index 00000000..0933cd64 --- /dev/null +++ b/Luogu/P4774/data/P4774_11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb5ea14883ec62fc5ec62be845ab5fa1be2c6fe63d369a062bca20dc6d205141 +size 157 diff --git a/Luogu/P4774/data/P4774_11.out b/Luogu/P4774/data/P4774_11.out new file mode 100644 index 00000000..6e684f11 --- /dev/null +++ b/Luogu/P4774/data/P4774_11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8c8b0ca7b48460892d87ea190c5cac66df3da7cf5337515fde9e20edf19c521 +size 44 diff --git a/Luogu/P4774/data/P4774_12.in b/Luogu/P4774/data/P4774_12.in new file mode 100644 index 00000000..fb1a3aa0 --- /dev/null +++ b/Luogu/P4774/data/P4774_12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:74afb237fcb6dc3930b0d076a52232810344af3978300dcc74211b29c2f7cdd4 +size 156 diff --git a/Luogu/P4774/data/P4774_12.out b/Luogu/P4774/data/P4774_12.out new file mode 100644 index 00000000..4e65cb41 --- /dev/null +++ b/Luogu/P4774/data/P4774_12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ebbd333f2279b32770ba14f3f4bea47c7f11e8fe967e3aca74162267aa261872 +size 45 diff --git a/Luogu/P4774/data/P4774_13.in b/Luogu/P4774/data/P4774_13.in new file mode 100644 index 00000000..74066e43 --- /dev/null +++ b/Luogu/P4774/data/P4774_13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac8ef4a18eb2b76159eba7211a6852725071edfa5e54e5e39804eff902e0092e +size 156 diff --git a/Luogu/P4774/data/P4774_13.out b/Luogu/P4774/data/P4774_13.out new file mode 100644 index 00000000..22e7d660 --- /dev/null +++ b/Luogu/P4774/data/P4774_13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:313bd367d2e60de7359ffb2edc5b9157fd4cc02da60a304aaab20b6e9d825c0c +size 43 diff --git a/Luogu/P4774/data/P4774_14.in b/Luogu/P4774/data/P4774_14.in new file mode 100644 index 00000000..6555bfab --- /dev/null +++ b/Luogu/P4774/data/P4774_14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e91ee042324b35461c5fdf1355e1b9c5feb214c325d7653df73ddacb6eef11fc +size 12260449 diff --git a/Luogu/P4774/data/P4774_14.out b/Luogu/P4774/data/P4774_14.out new file mode 100644 index 00000000..d3013a08 --- /dev/null +++ b/Luogu/P4774/data/P4774_14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:196a6367cf8d9443e423b72ef33ef19a2b82c25e3ae4076d318ad8be8b44f92c +size 20 diff --git a/Luogu/P4774/data/P4774_15.in b/Luogu/P4774/data/P4774_15.in new file mode 100644 index 00000000..bc759591 --- /dev/null +++ b/Luogu/P4774/data/P4774_15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7c6efeb315bee58465f4c70c22743ee69efc59ca748c5ce07cc852705e82c8b +size 12250126 diff --git a/Luogu/P4774/data/P4774_15.out b/Luogu/P4774/data/P4774_15.out new file mode 100644 index 00000000..da7261e8 --- /dev/null +++ b/Luogu/P4774/data/P4774_15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec0b1115e6094218fd552ea189c809641999917150f2fb4773fd9bb17bc52b73 +size 20 diff --git a/Luogu/P4774/data/P4774_16.in b/Luogu/P4774/data/P4774_16.in new file mode 100644 index 00000000..5a6abb72 --- /dev/null +++ b/Luogu/P4774/data/P4774_16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a35f88f0d1e75589d1629b112efc44419c18355e722db189d8293b2f52434af +size 9383793 diff --git a/Luogu/P4774/data/P4774_16.out b/Luogu/P4774/data/P4774_16.out new file mode 100644 index 00000000..f1e55270 --- /dev/null +++ b/Luogu/P4774/data/P4774_16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9bafe0436395d4480c93a2083e8293f151a52b8aba8a8bc1735445f27c5a9ed +size 61 diff --git a/Luogu/P4774/data/P4774_17.in b/Luogu/P4774/data/P4774_17.in new file mode 100644 index 00000000..0da0e78e --- /dev/null +++ b/Luogu/P4774/data/P4774_17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c08f0b13ff64946bb460ae2b5f59b5799622d653df7ee3d827da6e27b58f78cb +size 9379464 diff --git a/Luogu/P4774/data/P4774_17.out b/Luogu/P4774/data/P4774_17.out new file mode 100644 index 00000000..1a38adbb --- /dev/null +++ b/Luogu/P4774/data/P4774_17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52df07d464e2248c41d82ad0b7aa643c2b447483ce076fa2626e12d1560612ac +size 62 diff --git a/Luogu/P4774/data/P4774_18.in b/Luogu/P4774/data/P4774_18.in new file mode 100644 index 00000000..85c49c00 --- /dev/null +++ b/Luogu/P4774/data/P4774_18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:19002b88eb808742063966e59d7c05a1a6b2f2eb9a2687bbdf4ccf1055bf56cd +size 10863839 diff --git a/Luogu/P4774/data/P4774_18.out b/Luogu/P4774/data/P4774_18.out new file mode 100644 index 00000000..e50505c3 --- /dev/null +++ b/Luogu/P4774/data/P4774_18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc2545ed935ada43b1baaeba8e5353fe21a1355c8a4b9d511b562d0b152044b3 +size 65 diff --git a/Luogu/P4774/data/P4774_19.in b/Luogu/P4774/data/P4774_19.in new file mode 100644 index 00000000..24cc26e1 --- /dev/null +++ b/Luogu/P4774/data/P4774_19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ad502c6c219830884f429ff50f08921be8d6087403102a0abc021e0d4f8c5fd +size 10795733 diff --git a/Luogu/P4774/data/P4774_19.out b/Luogu/P4774/data/P4774_19.out new file mode 100644 index 00000000..982986a8 --- /dev/null +++ b/Luogu/P4774/data/P4774_19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:210a4597d8166edbdd3e4f68100c48a04593fc4ad58603edc79b8c11e61069b6 +size 65 diff --git a/Luogu/P4774/data/P4774_2.in b/Luogu/P4774/data/P4774_2.in new file mode 100644 index 00000000..c46c4a70 --- /dev/null +++ b/Luogu/P4774/data/P4774_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b621e52ea7b5c405574248458c5d7c206ef4540d1f02b0f0b3c981f71f764056 +size 4416720 diff --git a/Luogu/P4774/data/P4774_2.out b/Luogu/P4774/data/P4774_2.out new file mode 100644 index 00000000..a6b878b3 --- /dev/null +++ b/Luogu/P4774/data/P4774_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b2a995842eeea3cb393e39678642eb0f540c3f4738317df3f929c7605dc9d1e2 +size 25 diff --git a/Luogu/P4774/data/P4774_20.in b/Luogu/P4774/data/P4774_20.in new file mode 100644 index 00000000..d3ad70f4 --- /dev/null +++ b/Luogu/P4774/data/P4774_20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98b1eb1cf7ac30a7784c971ff9f1638bffd31b793b973b1fe07e239badee6764 +size 10696590 diff --git a/Luogu/P4774/data/P4774_20.out b/Luogu/P4774/data/P4774_20.out new file mode 100644 index 00000000..ce7dffe9 --- /dev/null +++ b/Luogu/P4774/data/P4774_20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1603c6050a24ccb2309d1494d8518c398e586cd2565fa6446f87809cca98889f +size 65 diff --git a/Luogu/P4774/data/P4774_3.in b/Luogu/P4774/data/P4774_3.in new file mode 100644 index 00000000..db7624e6 --- /dev/null +++ b/Luogu/P4774/data/P4774_3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70b4f7aede3856d00ae4b6a070487b5fb37a9eea1db01f73950097426311bddd +size 6322674 diff --git a/Luogu/P4774/data/P4774_3.out b/Luogu/P4774/data/P4774_3.out new file mode 100644 index 00000000..56d09ade --- /dev/null +++ b/Luogu/P4774/data/P4774_3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51aa1a5498d594cd381445169a6a3de596f72bb6300535d70b4ccfa7dfbf9f96 +size 25 diff --git a/Luogu/P4774/data/P4774_4.in b/Luogu/P4774/data/P4774_4.in new file mode 100644 index 00000000..dd9d850b --- /dev/null +++ b/Luogu/P4774/data/P4774_4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3e33d747b5b91fa56bc8098fcd03650ac1bb27010896ce80c3157122dea7f23 +size 6346146 diff --git a/Luogu/P4774/data/P4774_4.out b/Luogu/P4774/data/P4774_4.out new file mode 100644 index 00000000..152d6f74 --- /dev/null +++ b/Luogu/P4774/data/P4774_4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72624ff6f937e7fe83ba550a77da0ed417a84c2d6860ec101c900fb4da87cd7d +size 25 diff --git a/Luogu/P4774/data/P4774_5.in b/Luogu/P4774/data/P4774_5.in new file mode 100644 index 00000000..133f7d51 --- /dev/null +++ b/Luogu/P4774/data/P4774_5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f95c62691ebd2abb59c8c9b11fc30b3e3ebc836ca5e3af1c7149cb2abf79d4bc +size 71785 diff --git a/Luogu/P4774/data/P4774_5.out b/Luogu/P4774/data/P4774_5.out new file mode 100644 index 00000000..e377d5d6 --- /dev/null +++ b/Luogu/P4774/data/P4774_5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3b527c77255efca95b8830a96e6c1485ea3dc96bbc1af86146a654c7029e813 +size 35 diff --git a/Luogu/P4774/data/P4774_6.in b/Luogu/P4774/data/P4774_6.in new file mode 100644 index 00000000..4a0a6b92 --- /dev/null +++ b/Luogu/P4774/data/P4774_6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f14eecff7ce70dec04ffff9a36a64594a18223c025c3e099d10bed9757ee193f +size 69095 diff --git a/Luogu/P4774/data/P4774_6.out b/Luogu/P4774/data/P4774_6.out new file mode 100644 index 00000000..6e59d67f --- /dev/null +++ b/Luogu/P4774/data/P4774_6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7c562828bfaab914a6f5dac96b7fecc02a4375a58d69c7e1a8b885e2fc9abb3 +size 35 diff --git a/Luogu/P4774/data/P4774_7.in b/Luogu/P4774/data/P4774_7.in new file mode 100644 index 00000000..9d2e98d1 --- /dev/null +++ b/Luogu/P4774/data/P4774_7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96e9b82693d3b90e6d4189c0272410c5fba08df9d01a7811c18759b8b48c1b30 +size 71080 diff --git a/Luogu/P4774/data/P4774_7.out b/Luogu/P4774/data/P4774_7.out new file mode 100644 index 00000000..bb501c95 --- /dev/null +++ b/Luogu/P4774/data/P4774_7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a4609c1823966393b64991db4f0d42fb7276f2c38f2c297c230bb429c234beb +size 35 diff --git a/Luogu/P4774/data/P4774_8.in b/Luogu/P4774/data/P4774_8.in new file mode 100644 index 00000000..8469ffc5 --- /dev/null +++ b/Luogu/P4774/data/P4774_8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a02fbe5871ed606ccf71aed466a54444d74d478400b4600078721750b41b9daa +size 156 diff --git a/Luogu/P4774/data/P4774_8.out b/Luogu/P4774/data/P4774_8.out new file mode 100644 index 00000000..fb7f33cc --- /dev/null +++ b/Luogu/P4774/data/P4774_8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b419e86467be50b9de95a1313ad781c88227ed07f1c2fcae2f9b2c56ae746e48 +size 44 diff --git a/Luogu/P4774/data/P4774_9.in b/Luogu/P4774/data/P4774_9.in new file mode 100644 index 00000000..abfe1795 --- /dev/null +++ b/Luogu/P4774/data/P4774_9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77aa05bf19cdd73862eea424187dc5d61a97503613c4a7c50862f881038961cd +size 156 diff --git a/Luogu/P4774/data/P4774_9.out b/Luogu/P4774/data/P4774_9.out new file mode 100644 index 00000000..2fad49d1 --- /dev/null +++ b/Luogu/P4774/data/P4774_9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a600ebdc735346b73454e86988fa0d686ddd8fda831d7ea8df4f61130ad5af88 +size 45