This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub ebi-fly13/Library
#define PROBLEM "https://judge.yosupo.jp/problem/exp_of_set_power_series" #include <iostream> #include <vector> #include "../../modint/modint.hpp" #include "../../set_function/exp_of_sps.hpp" using mint = ebi::modint998244353; int main() { int n; std::cin >> n; std::vector<mint> b(1 << n); for (int i = 0; i < (1 << n); i++) { int x; std::cin >> x; b[i] = x; } auto c = ebi::exp_of_sps<mint, 20>(b); for (int i = 0; i < (1 << n); i++) { std::cout << c[i].val() << " \n"[i == (1 << n) - 1]; } }
#line 1 "test/set_function/Exp_of_Set_Power_Series.test.cpp" #define PROBLEM "https://judge.yosupo.jp/problem/exp_of_set_power_series" #include <iostream> #include <vector> #line 2 "modint/modint.hpp" #include <cassert> #line 5 "modint/modint.hpp" #line 2 "modint/base.hpp" #include <concepts> #line 5 "modint/base.hpp" #include <utility> namespace ebi { template <class T> concept Modint = requires(T a, T b) { a + b; a - b; a * b; a / b; a.inv(); a.val(); a.pow(std::declval<long long>()); T::mod(); }; template <Modint mint> std::istream &operator>>(std::istream &os, mint &a) { long long x; os >> x; a = x; return os; } template <Modint mint> std::ostream &operator<<(std::ostream &os, const mint &a) { return os << a.val(); } } // namespace ebi #line 7 "modint/modint.hpp" namespace ebi { template <int m> struct static_modint { private: using modint = static_modint; public: static constexpr int mod() { return m; } static constexpr modint raw(int v) { modint x; x._v = v; return x; } constexpr static_modint() : _v(0) {} constexpr static_modint(long long v) { v %= (long long)umod(); if (v < 0) v += (long long)umod(); _v = (unsigned int)v; } constexpr unsigned int val() const { return _v; } constexpr unsigned int value() const { return val(); } constexpr modint &operator++() { _v++; if (_v == umod()) _v = 0; return *this; } constexpr modint &operator--() { if (_v == 0) _v = umod(); _v--; return *this; } constexpr modint operator++(int) { modint res = *this; ++*this; return res; } constexpr modint operator--(int) { modint res = *this; --*this; return res; } constexpr modint &operator+=(const modint &rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } constexpr modint &operator-=(const modint &rhs) { _v -= rhs._v; if (_v >= umod()) _v += umod(); return *this; } constexpr modint &operator*=(const modint &rhs) { unsigned long long x = _v; x *= rhs._v; _v = (unsigned int)(x % (unsigned long long)umod()); return *this; } constexpr modint &operator/=(const modint &rhs) { return *this = *this * rhs.inv(); } constexpr modint operator+() const { return *this; } constexpr modint operator-() const { return modint() - *this; } constexpr modint pow(long long n) const { assert(0 <= n); modint x = *this, res = 1; while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } constexpr modint inv() const { assert(_v); return pow(umod() - 2); } friend modint operator+(const modint &lhs, const modint &rhs) { return modint(lhs) += rhs; } friend modint operator-(const modint &lhs, const modint &rhs) { return modint(lhs) -= rhs; } friend modint operator*(const modint &lhs, const modint &rhs) { return modint(lhs) *= rhs; } friend modint operator/(const modint &lhs, const modint &rhs) { return modint(lhs) /= rhs; } friend bool operator==(const modint &lhs, const modint &rhs) { return lhs.val() == rhs.val(); } friend bool operator!=(const modint &lhs, const modint &rhs) { return !(lhs == rhs); } private: unsigned int _v = 0; static constexpr unsigned int umod() { return m; } }; using modint998244353 = static_modint<998244353>; using modint1000000007 = static_modint<1000000007>; } // namespace ebi #line 2 "set_function/exp_of_sps.hpp" #line 5 "set_function/exp_of_sps.hpp" #line 2 "convolution/subset_convolution.hpp" /* refernce: https://www.slideshare.net/wata_orz/ss-12131479 https://37zigen.com/subset-convolution/ */ #include <array> #include <bit> #line 12 "convolution/subset_convolution.hpp" #line 2 "set_function/ranked_subset_transform.hpp" #line 7 "set_function/ranked_subset_transform.hpp" namespace ebi { template <class T, int LIM = 20> std::vector<std::array<T, LIM + 1>> ranked_zeta(const std::vector<T> &f) { int n = std::bit_width(f.size()) - 1; assert(n <= LIM); assert((int)f.size() == (1 << n)); std::vector<std::array<T, LIM + 1>> rf(1 << n); for (int s = 0; s < (1 << n); s++) rf[s][std::popcount((unsigned int)(s))] = f[s]; for (int i = 0; i < n; i++) { int w = 1 << i; for (int p = 0; p < (1 << n); p += 2 * w) { for (int s = p; s < p + w; s++) { int t = s | (1 << i); for (int d = 0; d <= n; d++) rf[t][d] += rf[s][d]; } } } return rf; } template <class T, int LIM = 20> std::vector<T> ranked_mobius(std::vector<std::array<T, LIM + 1>> rf) { int n = std::bit_width(rf.size()) - 1; assert((int)rf.size() == (1 << n)); for (int i = 0; i < n; i++) { int w = 1 << i; for (int p = 0; p < (1 << n); p += 2 * w) { for (int s = p; s < p + w; s++) { int t = s | (1 << i); for (int d = 0; d <= n; d++) rf[t][d] -= rf[s][d]; } } } std::vector<T> f(1 << n); for (int s = 0; s < (1 << n); s++) { f[s] = rf[s][std::popcount((unsigned int)(s))]; } return f; } } // namespace ebi #line 14 "convolution/subset_convolution.hpp" namespace ebi { template <class T, int LIM = 20> std::vector<T> subset_convolution(const std::vector<T> &a, const std::vector<T> &b) { auto ra = ranked_zeta<T, LIM>(a); auto rb = ranked_zeta<T, LIM>(b); int n = std::bit_width(a.size()) - 1; for (int s = (1 << n) - 1; s >= 0; s--) { auto &f = ra[s]; const auto &g = rb[s]; for (int d = n; d >= 0; d--) { T x = 0; for (int i = 0; i <= d; i++) { x += f[i] * g[d - i]; } f[d] = x; } } return ranked_mobius<T, LIM>(ra); } } // namespace ebi #line 7 "set_function/exp_of_sps.hpp" namespace ebi { template <class T, int LIM> std::vector<T> exp_of_sps(const std::vector<T> &a) { int n = std::bit_width(a.size()) - 1; assert(n <= LIM); assert((int)a.size() == (1 << n)); std::vector<T> fa(1 << n); fa[0] = T(1); for (int i = 0; i < n; i++) { std::vector<T> s = {a.begin() + (1 << i), a.begin() + (2 << i)}; std::vector<T> t = {fa.begin(), fa.begin() + (1 << i)}; auto c = subset_convolution<T, LIM>(s, t); std::copy(c.begin(), c.end(), fa.begin() + (1 << i)); } return fa; } } // namespace ebi #line 8 "test/set_function/Exp_of_Set_Power_Series.test.cpp" using mint = ebi::modint998244353; int main() { int n; std::cin >> n; std::vector<mint> b(1 << n); for (int i = 0; i < (1 << n); i++) { int x; std::cin >> x; b[i] = x; } auto c = ebi::exp_of_sps<mint, 20>(b); for (int i = 0; i < (1 << n); i++) { std::cout << c[i].val() << " \n"[i == (1 << n) - 1]; } }