From cb93cd2db3bffb6f31d3484f54e08fe3e5ad0072 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 27 Nov 2022 21:40:45 +0800 Subject: [PATCH] =?UTF-8?q?#108.=20=E5=A4=9A=E9=A1=B9=E5=BC=8F=E4=B9=98?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1645097 --- LibreOJ/108/108.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ LibreOJ/108/data/1.in | 3 ++ LibreOJ/108/data/1.out | 3 ++ LibreOJ/108/data/10.in | 3 ++ LibreOJ/108/data/10.out | 3 ++ LibreOJ/108/data/11.in | 3 ++ LibreOJ/108/data/11.out | 3 ++ LibreOJ/108/data/12.in | 3 ++ LibreOJ/108/data/12.out | 3 ++ LibreOJ/108/data/13.in | 3 ++ LibreOJ/108/data/13.out | 3 ++ LibreOJ/108/data/14.in | 3 ++ LibreOJ/108/data/14.out | 3 ++ LibreOJ/108/data/15.in | 3 ++ LibreOJ/108/data/15.out | 3 ++ LibreOJ/108/data/16.in | 3 ++ LibreOJ/108/data/16.out | 3 ++ LibreOJ/108/data/17.in | 3 ++ LibreOJ/108/data/17.out | 3 ++ LibreOJ/108/data/18.in | 3 ++ LibreOJ/108/data/18.out | 3 ++ LibreOJ/108/data/19.in | 3 ++ LibreOJ/108/data/19.out | 3 ++ LibreOJ/108/data/2.in | 3 ++ LibreOJ/108/data/2.out | 3 ++ LibreOJ/108/data/20.in | 3 ++ LibreOJ/108/data/20.out | 3 ++ LibreOJ/108/data/3.in | 3 ++ LibreOJ/108/data/3.out | 3 ++ LibreOJ/108/data/4.in | 3 ++ LibreOJ/108/data/4.out | 3 ++ LibreOJ/108/data/5.in | 3 ++ LibreOJ/108/data/5.out | 3 ++ LibreOJ/108/data/6.in | 3 ++ LibreOJ/108/data/6.out | 3 ++ LibreOJ/108/data/7.in | 3 ++ LibreOJ/108/data/7.out | 3 ++ LibreOJ/108/data/8.in | 3 ++ LibreOJ/108/data/8.out | 3 ++ LibreOJ/108/data/9.in | 3 ++ LibreOJ/108/data/9.out | 3 ++ 41 files changed, 192 insertions(+) create mode 100644 LibreOJ/108/108.cpp create mode 100644 LibreOJ/108/data/1.in create mode 100644 LibreOJ/108/data/1.out create mode 100644 LibreOJ/108/data/10.in create mode 100644 LibreOJ/108/data/10.out create mode 100644 LibreOJ/108/data/11.in create mode 100644 LibreOJ/108/data/11.out create mode 100644 LibreOJ/108/data/12.in create mode 100644 LibreOJ/108/data/12.out create mode 100644 LibreOJ/108/data/13.in create mode 100644 LibreOJ/108/data/13.out create mode 100644 LibreOJ/108/data/14.in create mode 100644 LibreOJ/108/data/14.out create mode 100644 LibreOJ/108/data/15.in create mode 100644 LibreOJ/108/data/15.out create mode 100644 LibreOJ/108/data/16.in create mode 100644 LibreOJ/108/data/16.out create mode 100644 LibreOJ/108/data/17.in create mode 100644 LibreOJ/108/data/17.out create mode 100644 LibreOJ/108/data/18.in create mode 100644 LibreOJ/108/data/18.out create mode 100644 LibreOJ/108/data/19.in create mode 100644 LibreOJ/108/data/19.out create mode 100644 LibreOJ/108/data/2.in create mode 100644 LibreOJ/108/data/2.out create mode 100644 LibreOJ/108/data/20.in create mode 100644 LibreOJ/108/data/20.out create mode 100644 LibreOJ/108/data/3.in create mode 100644 LibreOJ/108/data/3.out create mode 100644 LibreOJ/108/data/4.in create mode 100644 LibreOJ/108/data/4.out create mode 100644 LibreOJ/108/data/5.in create mode 100644 LibreOJ/108/data/5.out create mode 100644 LibreOJ/108/data/6.in create mode 100644 LibreOJ/108/data/6.out create mode 100644 LibreOJ/108/data/7.in create mode 100644 LibreOJ/108/data/7.out create mode 100644 LibreOJ/108/data/8.in create mode 100644 LibreOJ/108/data/8.out create mode 100644 LibreOJ/108/data/9.in create mode 100644 LibreOJ/108/data/9.out diff --git a/LibreOJ/108/108.cpp b/LibreOJ/108/108.cpp new file mode 100644 index 00000000..d0882a69 --- /dev/null +++ b/LibreOJ/108/108.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const double PI = std::acos(-1); + +void FFT(std::vector>& a) { + if (a.size() == 1) return; + + int m = a.size() >> 1; + std::vector> a0, a1; + + for (int i = 0; i < m; i++) { + a0.emplace_back(a[i << 1]); + a1.emplace_back(a[i << 1 | 1]); + } + + FFT(a0), FFT(a1); + + std::complex + w0{std::cos(PI / m), std::sin(PI / m)}, + w1{1.0, 0.0}; + + for (int i = 0; i < m; i++) { + a[i] = a0[i] + w1 * a1[i]; + a[i + m] = a0[i] - w1 * a1[i]; + w1 *= w0; + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n, m; + + cin >> n >> m; + + int k = 1 << (std::__lg(n + m) + 1); + std::vector> f(k), g(k); + + for (int i = 0; i <= n; i++) { + cin >> f[i]; + } + + for (int i = 0; i <= m; i++) { + cin >> g[i]; + } + + FFT(f), FFT(g); + + for (int i = 0; i < k; i++) { + f[i] *= g[i]; + } + + FFT(f); + std::reverse(f.begin() + 1, f.end()); + + for (int i = 0; i <= n + m; i++) { + cout << static_cast(std::round(f[i].real() / k)) << ' '; + } + + cout << endl; + + return 0; +} diff --git a/LibreOJ/108/data/1.in b/LibreOJ/108/data/1.in new file mode 100644 index 00000000..ffe0b529 --- /dev/null +++ b/LibreOJ/108/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e408b01d3a187b99a62cd6e312729bea8f2159a24a960e17d560f0f5a3fad32 +size 400018 diff --git a/LibreOJ/108/data/1.out b/LibreOJ/108/data/1.out new file mode 100644 index 00000000..de087334 --- /dev/null +++ b/LibreOJ/108/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:790c3e8ed051204e43e3a2a1667635cfd3de974b7f34dc06f8464ee5d44767bf +size 1490574 diff --git a/LibreOJ/108/data/10.in b/LibreOJ/108/data/10.in new file mode 100644 index 00000000..6597f754 --- /dev/null +++ b/LibreOJ/108/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ddcc31c5ce8d843f3735067ccec4a89011b752257b916d411d240730dbf0881 +size 400018 diff --git a/LibreOJ/108/data/10.out b/LibreOJ/108/data/10.out new file mode 100644 index 00000000..885774d0 --- /dev/null +++ b/LibreOJ/108/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee6c23d2728874d6c33caa70a2e8cc5da76fdb850ff7158888a100ee2d6f7bf8 +size 1490916 diff --git a/LibreOJ/108/data/11.in b/LibreOJ/108/data/11.in new file mode 100644 index 00000000..8424e2f8 --- /dev/null +++ b/LibreOJ/108/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5cf623be14758a1fba06e7b73aa2b0113343e4ca7f66151266124d04e54fea07 +size 400018 diff --git a/LibreOJ/108/data/11.out b/LibreOJ/108/data/11.out new file mode 100644 index 00000000..501c15dc --- /dev/null +++ b/LibreOJ/108/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86bb67f958977ed7f404bce64e76addecc91c853ca9eb290d95007d66503ff99 +size 1490171 diff --git a/LibreOJ/108/data/12.in b/LibreOJ/108/data/12.in new file mode 100644 index 00000000..8424e2f8 --- /dev/null +++ b/LibreOJ/108/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5cf623be14758a1fba06e7b73aa2b0113343e4ca7f66151266124d04e54fea07 +size 400018 diff --git a/LibreOJ/108/data/12.out b/LibreOJ/108/data/12.out new file mode 100644 index 00000000..501c15dc --- /dev/null +++ b/LibreOJ/108/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86bb67f958977ed7f404bce64e76addecc91c853ca9eb290d95007d66503ff99 +size 1490171 diff --git a/LibreOJ/108/data/13.in b/LibreOJ/108/data/13.in new file mode 100644 index 00000000..373f1675 --- /dev/null +++ b/LibreOJ/108/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47f4276cb852281f65fa94cb12309c91d2f5eaf364d597a0bb12339b695b350f +size 400018 diff --git a/LibreOJ/108/data/13.out b/LibreOJ/108/data/13.out new file mode 100644 index 00000000..ee3e46b5 --- /dev/null +++ b/LibreOJ/108/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54de160e1907889fcf5e1cd558bd07e96db655660e644df3e17d4efb16bc1be0 +size 1490493 diff --git a/LibreOJ/108/data/14.in b/LibreOJ/108/data/14.in new file mode 100644 index 00000000..21e3ef88 --- /dev/null +++ b/LibreOJ/108/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96b2c3dea5a18ef2af169f5b5c784b5bb6c77723eb9dec9837bb02c135063b5c +size 400018 diff --git a/LibreOJ/108/data/14.out b/LibreOJ/108/data/14.out new file mode 100644 index 00000000..710dbed7 --- /dev/null +++ b/LibreOJ/108/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:daae2d98e0bac105fd4a54c6166634cb4669aeb82302fff7401c9e34574cfdc0 +size 1490080 diff --git a/LibreOJ/108/data/15.in b/LibreOJ/108/data/15.in new file mode 100644 index 00000000..21e3ef88 --- /dev/null +++ b/LibreOJ/108/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96b2c3dea5a18ef2af169f5b5c784b5bb6c77723eb9dec9837bb02c135063b5c +size 400018 diff --git a/LibreOJ/108/data/15.out b/LibreOJ/108/data/15.out new file mode 100644 index 00000000..710dbed7 --- /dev/null +++ b/LibreOJ/108/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:daae2d98e0bac105fd4a54c6166634cb4669aeb82302fff7401c9e34574cfdc0 +size 1490080 diff --git a/LibreOJ/108/data/16.in b/LibreOJ/108/data/16.in new file mode 100644 index 00000000..3db55d2f --- /dev/null +++ b/LibreOJ/108/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23a1d727400529a184b80c51cc9a6f75c566e2f9425b6f4e491d2a1acbedab91 +size 400018 diff --git a/LibreOJ/108/data/16.out b/LibreOJ/108/data/16.out new file mode 100644 index 00000000..dd024271 --- /dev/null +++ b/LibreOJ/108/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:892e754622031919de4e477f54dd93a6149709bf3f13eff13148e4cf56d77af8 +size 1490031 diff --git a/LibreOJ/108/data/17.in b/LibreOJ/108/data/17.in new file mode 100644 index 00000000..8bd30b19 --- /dev/null +++ b/LibreOJ/108/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15f72a24562c29d01915be50cebc9140a86ab0fe71ffad69008e18533953932e +size 400018 diff --git a/LibreOJ/108/data/17.out b/LibreOJ/108/data/17.out new file mode 100644 index 00000000..f12751d5 --- /dev/null +++ b/LibreOJ/108/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6384f3397d04ce8912ab0f7074aefdf2e8fe401dcae8de08d57cda00bd3d74cf +size 1490573 diff --git a/LibreOJ/108/data/18.in b/LibreOJ/108/data/18.in new file mode 100644 index 00000000..8bd30b19 --- /dev/null +++ b/LibreOJ/108/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15f72a24562c29d01915be50cebc9140a86ab0fe71ffad69008e18533953932e +size 400018 diff --git a/LibreOJ/108/data/18.out b/LibreOJ/108/data/18.out new file mode 100644 index 00000000..f12751d5 --- /dev/null +++ b/LibreOJ/108/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6384f3397d04ce8912ab0f7074aefdf2e8fe401dcae8de08d57cda00bd3d74cf +size 1490573 diff --git a/LibreOJ/108/data/19.in b/LibreOJ/108/data/19.in new file mode 100644 index 00000000..79c1febb --- /dev/null +++ b/LibreOJ/108/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a2c305ba2504e8db6dec817fce9a3f9a403228f48de9747eec7d03fc37dd379 +size 400018 diff --git a/LibreOJ/108/data/19.out b/LibreOJ/108/data/19.out new file mode 100644 index 00000000..3cc7d1e3 --- /dev/null +++ b/LibreOJ/108/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4878b234674eca6b52f3a0c1e603e8e1f775a91a435b41bc466e70d95ce2213 +size 1489609 diff --git a/LibreOJ/108/data/2.in b/LibreOJ/108/data/2.in new file mode 100644 index 00000000..54e91da1 --- /dev/null +++ b/LibreOJ/108/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e985ce2a344c4ae03883227284fa33a0851024fbdc507b3eca11b9f63ce24ae +size 400018 diff --git a/LibreOJ/108/data/2.out b/LibreOJ/108/data/2.out new file mode 100644 index 00000000..dcb9853d --- /dev/null +++ b/LibreOJ/108/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e344c845d4b89304e9c98b0a1450315eba00d703ed1457e6bfd59e6c93c5ff91 +size 1490744 diff --git a/LibreOJ/108/data/20.in b/LibreOJ/108/data/20.in new file mode 100644 index 00000000..f3db1302 --- /dev/null +++ b/LibreOJ/108/data/20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8a93a9f199c7caaf5412dceaee86ad7c9aee138a315c4d9dcc90208c4d71e0f3 +size 400018 diff --git a/LibreOJ/108/data/20.out b/LibreOJ/108/data/20.out new file mode 100644 index 00000000..04a46d35 --- /dev/null +++ b/LibreOJ/108/data/20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:452c372c23b791f38099f24a13e0f18a836dbab846e56c010cdb26b60f51396c +size 1490279 diff --git a/LibreOJ/108/data/3.in b/LibreOJ/108/data/3.in new file mode 100644 index 00000000..54e91da1 --- /dev/null +++ b/LibreOJ/108/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e985ce2a344c4ae03883227284fa33a0851024fbdc507b3eca11b9f63ce24ae +size 400018 diff --git a/LibreOJ/108/data/3.out b/LibreOJ/108/data/3.out new file mode 100644 index 00000000..dcb9853d --- /dev/null +++ b/LibreOJ/108/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e344c845d4b89304e9c98b0a1450315eba00d703ed1457e6bfd59e6c93c5ff91 +size 1490744 diff --git a/LibreOJ/108/data/4.in b/LibreOJ/108/data/4.in new file mode 100644 index 00000000..e5f10fc8 --- /dev/null +++ b/LibreOJ/108/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97f64146bccce9b9de671264bba225b266600e823008f99e86231f907b3c7140 +size 400018 diff --git a/LibreOJ/108/data/4.out b/LibreOJ/108/data/4.out new file mode 100644 index 00000000..a51b406d --- /dev/null +++ b/LibreOJ/108/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4385b47201b01dc9507ceaaf249b1b6489599f04403bf389b6809de78d55912 +size 1490764 diff --git a/LibreOJ/108/data/5.in b/LibreOJ/108/data/5.in new file mode 100644 index 00000000..694368af --- /dev/null +++ b/LibreOJ/108/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9673bdbe34b608e9ed37bbecefef220eb4648dcc6f39b0dff8a1b5138d6a1239 +size 400018 diff --git a/LibreOJ/108/data/5.out b/LibreOJ/108/data/5.out new file mode 100644 index 00000000..99475b18 --- /dev/null +++ b/LibreOJ/108/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d508cf3c67199ddc88efa26bcc3b76d74483c6312a32ba21b723f7aee0229ccf +size 1490263 diff --git a/LibreOJ/108/data/6.in b/LibreOJ/108/data/6.in new file mode 100644 index 00000000..694368af --- /dev/null +++ b/LibreOJ/108/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9673bdbe34b608e9ed37bbecefef220eb4648dcc6f39b0dff8a1b5138d6a1239 +size 400018 diff --git a/LibreOJ/108/data/6.out b/LibreOJ/108/data/6.out new file mode 100644 index 00000000..99475b18 --- /dev/null +++ b/LibreOJ/108/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d508cf3c67199ddc88efa26bcc3b76d74483c6312a32ba21b723f7aee0229ccf +size 1490263 diff --git a/LibreOJ/108/data/7.in b/LibreOJ/108/data/7.in new file mode 100644 index 00000000..39eda0fc --- /dev/null +++ b/LibreOJ/108/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d39f24cf386dd6ea9ee7446fd589e690d68aa9230336826b72e1c41b63fcfab9 +size 400018 diff --git a/LibreOJ/108/data/7.out b/LibreOJ/108/data/7.out new file mode 100644 index 00000000..5ebdcde9 --- /dev/null +++ b/LibreOJ/108/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:26686090ed0ca3d2874ce6baa7a72e73375828f96f030d70959afa48dbe87bc9 +size 1490157 diff --git a/LibreOJ/108/data/8.in b/LibreOJ/108/data/8.in new file mode 100644 index 00000000..b4a20866 --- /dev/null +++ b/LibreOJ/108/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4eee39a5dc3910e31aba40fb5385b7ba137655941bbebf8953c0318bf444834 +size 400018 diff --git a/LibreOJ/108/data/8.out b/LibreOJ/108/data/8.out new file mode 100644 index 00000000..e82362d0 --- /dev/null +++ b/LibreOJ/108/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3379a0e20a374a85d24ea5bba715b3d0f9c58b4d9d09e17278da5f7e53d09f2c +size 1489901 diff --git a/LibreOJ/108/data/9.in b/LibreOJ/108/data/9.in new file mode 100644 index 00000000..b4a20866 --- /dev/null +++ b/LibreOJ/108/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4eee39a5dc3910e31aba40fb5385b7ba137655941bbebf8953c0318bf444834 +size 400018 diff --git a/LibreOJ/108/data/9.out b/LibreOJ/108/data/9.out new file mode 100644 index 00000000..e82362d0 --- /dev/null +++ b/LibreOJ/108/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3379a0e20a374a85d24ea5bba715b3d0f9c58b4d9d09e17278da5f7e53d09f2c +size 1489901