Submit Info #2613

Problem Lang User Status Time Memory
Exp of Formal Power Series cpp risujiroh AC 223 ms 26.73 MiB

ケース詳細
Name Status Time Memory
example_00 AC 5 ms 0.62 MiB
max_random_00 AC 221 ms 26.70 MiB
max_random_01 AC 222 ms 26.73 MiB
max_random_02 AC 221 ms 26.65 MiB
max_random_03 AC 221 ms 26.69 MiB
max_random_04 AC 223 ms 26.66 MiB
random_00 AC 212 ms 23.68 MiB
random_01 AC 218 ms 25.73 MiB
random_02 AC 28 ms 3.73 MiB
random_03 AC 215 ms 24.74 MiB
random_04 AC 203 ms 20.79 MiB

#include <bits/stdc++.h> using namespace std; #ifdef __linux__ #define getchar getchar_unlocked #define putchar putchar_unlocked #endif template <class Z> Z getint() { char c = getchar(); bool neg = c == '-'; Z res = neg ? 0 : c - '0'; while (isdigit(c = getchar())) res = res * 10 + (c - '0'); return neg ? -res : res; } template <class Z> void putint(Z a, char c = '\n') { if (a < 0) putchar('-'), a = -a; int d[40], i = 0; do d[i++] = a % 10; while (a /= 10); while (i--) putchar('0' + d[i]); putchar(c); } template <class T> vector<T> operator-(vector<T> a) { for (auto&& e : a) e = -e; return a; } template <class T> vector<T>& operator+=(vector<T>& l, const vector<T>& r) { l.resize(max(l.size(), r.size())); for (int i = 0; i < (int)r.size(); ++i) l[i] += r[i]; return l; } template <class T> vector<T> operator+(vector<T> l, const vector<T>& r) { return l += r; } template <class T> vector<T>& operator-=(vector<T>& l, const vector<T>& r) { l.resize(max(l.size(), r.size())); for (int i = 0; i < (int)r.size(); ++i) l[i] -= r[i]; return l; } template <class T> vector<T> operator-(vector<T> l, const vector<T>& r) { return l -= r; } template <class T> vector<T>& operator<<=(vector<T>& a, size_t n) { return a.insert(begin(a), n, 0), a; } template <class T> vector<T> operator<<(vector<T> a, size_t n) { return a <<= n; } template <class T> vector<T>& operator>>=(vector<T>& a, size_t n) { return a.erase(begin(a), begin(a) + min(a.size(), n)), a; } template <class T> vector<T> operator>>(vector<T> a, size_t n) { return a >>= n; } template <class T> vector<T> operator*(const vector<T>& l, const vector<T>& r) { if (l.empty() or r.empty()) return {}; vector<T> res(l.size() + r.size() - 1); for (int i = 0; i < (int)l.size(); ++i) for (int j = 0; j < (int)r.size(); ++j) res[i + j] += l[i] * r[j]; return res; } template <class T> vector<T>& operator*=(vector<T>& l, const vector<T>& r) { return l = l * r; } template <class T> vector<T> inverse(const vector<T>& a) { assert(not a.empty() and not (a[0] == 0)); vector<T> b{1 / a[0]}; while (b.size() < a.size()) { vector<T> x(begin(a), begin(a) + min(a.size(), 2 * b.size())); x *= b * b; b.resize(2 * b.size()); for (auto i = b.size() / 2; i < min(x.size(), b.size()); ++i) b[i] = -x[i]; } return {begin(b), begin(b) + a.size()}; } template <class T> vector<T> operator/(vector<T> l, vector<T> r) { if (l.size() < r.size()) return {}; reverse(begin(l), end(l)), reverse(begin(r), end(r)); int n = l.size() - r.size() + 1; l.resize(n), r.resize(n); l *= inverse(r); return {rend(l) - n, rend(l)}; } template <class T> vector<T>& operator/=(vector<T>& l, const vector<T>& r) { return l = l / r; } template <class T> vector<T> operator%(vector<T> l, const vector<T>& r) { if (l.size() < r.size()) return l; l -= l / r * r; return {begin(l), begin(l) + (r.size() - 1)}; } template <class T> vector<T>& operator%=(vector<T>& l, const vector<T>& r) { return l = l % r; } template <class T> vector<T> derivative(const vector<T>& a) { vector<T> res(max((int)a.size() - 1, 0)); for (int i = 0; i < (int)res.size(); ++i) res[i] = (i + 1) * a[i + 1]; return res; } template <class T> vector<T> primitive(const vector<T>& a) { vector<T> res(a.size() + 1); for (int i = 1; i < (int)res.size(); ++i) res[i] = a[i - 1] / i; return res; } template <class T> vector<T> logarithm(const vector<T>& a) { assert(not a.empty() and a[0] == 1); auto res = primitive(derivative(a) * inverse(a)); return {begin(res), begin(res) + a.size()}; } template <class T> vector<T> exponent(const vector<T>& a) { assert(a.empty() or a[0] == 0); vector<T> b{1}; while (b.size() < a.size()) { vector<T> x(begin(a), begin(a) + min(a.size(), 2 * b.size())); x[0] += 1; b.resize(2 * b.size()); x -= logarithm(b); x *= {begin(b), begin(b) + b.size() / 2}; for (auto i = b.size() / 2; i < min(x.size(), b.size()); ++i) b[i] = x[i]; } return {begin(b), begin(b) + a.size()}; } template <class T, class F = multiplies<T>> T power(T a, long long n, F op = multiplies<T>(), T e = {1}) { assert(n >= 0); T res = e; while (n) { if (n & 1) res = op(res, a); if (n >>= 1) a = op(a, a); } return res; } template <unsigned Mod> struct Modular { using M = Modular; unsigned v; Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {} M operator-() const { return M() -= *this; } M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; } M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; } M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; } M& operator/=(M r) { return *this *= power(r, Mod - 2); } friend M operator+(M l, M r) { return l += r; } friend M operator-(M l, M r) { return l -= r; } friend M operator*(M l, M r) { return l *= r; } friend M operator/(M l, M r) { return l /= r; } friend bool operator==(M l, M r) { return l.v == r.v; } }; template <unsigned Mod> void ntt(vector<Modular<Mod>>& a, bool inverse) { static vector<Modular<Mod>> dt(30), idt(30); if (dt[0] == 0) { Modular<Mod> root = 2; while (power(root, (Mod - 1) / 2) == 1) root += 1; for (int i = 0; i < 30; ++i) dt[i] = -power(root, (Mod - 1) >> (i + 2)), idt[i] = 1 / dt[i]; } int n = a.size(); assert((n & (n - 1)) == 0); if (not inverse) { for (int w = n; w >>= 1; ) { Modular<Mod> t = 1; for (int s = 0, k = 0; s < n; s += 2 * w) { for (int i = s, j = s + w; i < s + w; ++i, ++j) { auto x = a[i], y = a[j] * t; if (x.v >= Mod) x.v -= Mod; a[i].v = x.v + y.v, a[j].v = x.v + (Mod - y.v); } t *= dt[__builtin_ctz(++k)]; } } } else { for (int w = 1; w < n; w *= 2) { Modular<Mod> t = 1; for (int s = 0, k = 0; s < n; s += 2 * w) { for (int i = s, j = s + w; i < s + w; ++i, ++j) { auto x = a[i], y = a[j]; a[i] = x + y, a[j].v = x.v + (Mod - y.v), a[j] *= t; } t *= idt[__builtin_ctz(++k)]; } } } auto c = 1 / Modular<Mod>(inverse ? n : 1); for (auto&& e : a) e *= c; } template <unsigned Mod> vector<Modular<Mod>> operator*(vector<Modular<Mod>> l, vector<Modular<Mod>> r) { if (l.empty() or r.empty()) return {}; int n = l.size(), m = r.size(), sz = 1 << __lg(2 * (n + m - 1) - 1); if (min(n, m) < 30) { vector<long long> res(n + m- 1); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) res[i + j] += (l[i] * r[j]).v; return {begin(res), end(res)}; } bool eq = l == r; l.resize(sz), ntt(l, false); if (eq) r = l; else r.resize(sz), ntt(r, false); for (int i = 0; i < sz; ++i) l[i] *= r[i]; ntt(l, true), l.resize(n + m - 1); return l; } template <unsigned Mod> vector<Modular<Mod>> inverse(const vector<Modular<Mod>>& a) { assert(not a.empty() and not (a[0] == 0)); vector<Modular<Mod>> b{1 / a[0]}; for (int m = 1; m < (int)a.size(); m *= 2) { vector<Modular<Mod>> x(begin(a), begin(a) + min<int>(a.size(), 2 * m)); auto y = b; x.resize(2 * m), ntt(x, false); y.resize(2 * m), ntt(y, false); for (int i = 0; i < 2 * m; ++i) x[i] *= y[i]; ntt(x, true); fill(begin(x), begin(x) + m, 0); ntt(x, false); for (int i = 0; i < 2 * m; ++i) x[i] *= -y[i]; ntt(x, true); b.insert(end(b), begin(x) + m, end(x)); } return {begin(b), begin(b) + a.size()}; } template <unsigned Mod> vector<Modular<Mod>> exponent(const vector<Modular<Mod>>& a) { assert(a.empty() or a[0] == 0); vector<Modular<Mod>> b{1, 1 < a.size() ? a[1] : 0}, c{1}, z1, z2{1, 1}; for (int m = 2; m < (int)a.size(); m *= 2) { auto y = b; y.resize(2 * m), ntt(y, false); z1 = z2; vector<Modular<Mod>> z(m); for (int i = 0; i < m; ++i) z[i] = y[i] * z1[i]; ntt(z, true); fill(begin(z), begin(z) + m / 2, 0); ntt(z, false); for (int i = 0; i < m; ++i) z[i] *= -z1[i]; ntt(z, true); c.insert(end(c), begin(z) + m / 2, end(z)); z2 = c, z2.resize(2 * m), ntt(z2, false); vector<Modular<Mod>> x(begin(a), begin(a) + min<int>(a.size(), m)); x = derivative(x), x.push_back(0), ntt(x, false); for (int i = 0; i < m; ++i) x[i] *= y[i]; ntt(x, true); x -= derivative(b); x.resize(2 * m); for (int i = 0; i < m - 1; ++i) x[m + i] = x[i], x[i] = 0; ntt(x, false); for (int i = 0; i < 2 * m; ++i) x[i] *= z2[i]; ntt(x, true); x = primitive(x), x.pop_back(); for (int i = m; i < min<int>(a.size(), 2 * m); ++i) x[i] += a[i]; fill(begin(x), begin(x) + m, 0); ntt(x, false); for (int i = 0; i < 2 * m; ++i) x[i] *= y[i]; ntt(x, true); b.insert(end(b), begin(x) + m, end(x)); } return {begin(b), begin(b) + a.size()}; } constexpr long long mod = 998244353; using Mint = Modular<mod>; vector<Mint> fact, inv_fact, minv; void prepare(int n) { fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1); for (int i = 0; i <= n; ++i) fact[i] = i ? i * fact[i - 1] : 1; inv_fact[n] = 1 / fact[n]; for (int i = n; i; --i) inv_fact[i - 1] = i * inv_fact[i]; for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1]; } Mint binom(int n, int k) { if (k < 0 or k > n) return 0; return fact[n] * inv_fact[k] * inv_fact[n - k]; } template<> Mint& Mint::operator/=(Mint r) { return *this *= r.v < minv.size() ? minv[r.v] : power(r, mod - 2); } int main() { int n = getint<int>(); vector<Mint> a(n); generate(begin(a), end(a), [] { return getint<int>(); }); prepare(2 * n); a = exponent(a); for (int i = 0; i < n; ++i) { putint(a[i].v, " \n"[i == n - 1]); } }