QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749439 | #1098. 多项式复合逆 | I_be_wanna | 10 ✓ | 246ms | 9120kb | C++20 | 32.4kb | 2024-11-15 00:49:33 | 2024-11-15 00:49:33 |
Judging History
answer
#line 1 "test/compositional_inverse_of_formal_power_series_large.0.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/compositional_inverse_of_formal_power_series_large"
#line 2 "fps_composition.hpp"
#line 2 "binomial.hpp"
#include <algorithm>
#include <vector>
template <typename Tp>
class Binomial {
std::vector<Tp> factorial_, invfactorial_;
Binomial() : factorial_{Tp(1)}, invfactorial_{Tp(1)} {}
void preprocess(int n) {
if (const int nn = factorial_.size(); nn < n) {
int k = nn;
while (k < n) k *= 2;
k = std::min<long long>(k, Tp::mod());
factorial_.resize(k);
invfactorial_.resize(k);
for (int i = nn; i < k; ++i) factorial_[i] = factorial_[i - 1] * i;
invfactorial_.back() = factorial_.back().inv();
for (int i = k - 2; i >= nn; --i) invfactorial_[i] = invfactorial_[i + 1] * (i + 1);
}
}
public:
static const Binomial &get(int n) {
static Binomial bin;
bin.preprocess(n);
return bin;
}
Tp binom(int n, int m) const {
return n < m ? Tp() : factorial_[n] * invfactorial_[m] * invfactorial_[n - m];
}
Tp inv(int n) const { return factorial_[n - 1] * invfactorial_[n]; }
Tp factorial(int n) const { return factorial_[n]; }
Tp inv_factorial(int n) const { return invfactorial_[n]; }
};
#line 2 "fft.hpp"
#line 4 "fft.hpp"
#include <cassert>
#include <iterator>
#include <memory>
#line 8 "fft.hpp"
template <typename Tp>
class FftInfo {
static Tp least_quadratic_nonresidue() {
for (int i = 2;; ++i)
if (Tp(i).pow((Tp::mod() - 1) / 2) == -1) return Tp(i);
}
const int ordlog2_;
const Tp zeta_;
const Tp invzeta_;
const Tp imag_;
const Tp invimag_;
mutable std::vector<Tp> root_;
mutable std::vector<Tp> invroot_;
FftInfo()
: ordlog2_(__builtin_ctzll(Tp::mod() - 1)),
zeta_(least_quadratic_nonresidue().pow((Tp::mod() - 1) >> ordlog2_)),
invzeta_(zeta_.inv()), imag_(zeta_.pow(1LL << (ordlog2_ - 2))), invimag_(-imag_),
root_{Tp(1), imag_}, invroot_{Tp(1), invimag_} {}
public:
static const FftInfo &get() {
static FftInfo info;
return info;
}
Tp imag() const { return imag_; }
Tp inv_imag() const { return invimag_; }
Tp zeta() const { return zeta_; }
Tp inv_zeta() const { return invzeta_; }
const std::vector<Tp> &root(int n) const {
// [0, n)
assert((n & (n - 1)) == 0);
if (const int s = root_.size(); s < n) {
root_.resize(n);
for (int i = __builtin_ctz(s); (1 << i) < n; ++i) {
const int j = 1 << i;
root_[j] = zeta_.pow(1LL << (ordlog2_ - i - 2));
for (int k = j + 1; k < j * 2; ++k) root_[k] = root_[k - j] * root_[j];
}
}
return root_;
}
const std::vector<Tp> &inv_root(int n) const {
// [0, n)
assert((n & (n - 1)) == 0);
if (const int s = invroot_.size(); s < n) {
invroot_.resize(n);
for (int i = __builtin_ctz(s); (1 << i) < n; ++i) {
const int j = 1 << i;
invroot_[j] = invzeta_.pow(1LL << (ordlog2_ - i - 2));
for (int k = j + 1; k < j * 2; ++k) invroot_[k] = invroot_[k - j] * invroot_[j];
}
}
return invroot_;
}
};
inline int fft_len(int n) {
--n;
n |= n >> 1, n |= n >> 2, n |= n >> 4, n |= n >> 8;
return (n | n >> 16) + 1;
}
template <typename Iterator>
inline void fft_n(Iterator a, int n) {
using Tp = typename std::iterator_traits<Iterator>::value_type;
assert((n & (n - 1)) == 0);
for (int j = 0; j < n / 2; ++j) {
auto u = a[j], v = a[j + n / 2];
a[j] = u + v, a[j + n / 2] = u - v;
}
auto &&root = FftInfo<Tp>::get().root(n / 2);
for (int i = n / 2; i >= 2; i /= 2) {
for (int j = 0; j < i / 2; ++j) {
auto u = a[j], v = a[j + i / 2];
a[j] = u + v, a[j + i / 2] = u - v;
}
for (int j = i, m = 1; j < n; j += i, ++m)
for (int k = j; k < j + i / 2; ++k) {
auto u = a[k], v = a[k + i / 2] * root[m];
a[k] = u + v, a[k + i / 2] = u - v;
}
}
}
template <typename Tp>
inline void fft(std::vector<Tp> &a) {
fft_n(a.begin(), a.size());
}
template <typename Iterator>
inline void inv_fft_n(Iterator a, int n) {
using Tp = typename std::iterator_traits<Iterator>::value_type;
assert((n & (n - 1)) == 0);
auto &&root = FftInfo<Tp>::get().inv_root(n / 2);
for (int i = 2; i < n; i *= 2) {
for (int j = 0; j < i / 2; ++j) {
auto u = a[j], v = a[j + i / 2];
a[j] = u + v, a[j + i / 2] = u - v;
}
for (int j = i, m = 1; j < n; j += i, ++m)
for (int k = j; k < j + i / 2; ++k) {
auto u = a[k], v = a[k + i / 2];
a[k] = u + v, a[k + i / 2] = (u - v) * root[m];
}
}
const Tp iv = Tp::mod() - Tp::mod() / n;
for (int j = 0; j < n / 2; ++j) {
auto u = a[j] * iv, v = a[j + n / 2] * iv;
a[j] = u + v, a[j + n / 2] = u - v;
}
}
template <typename Tp>
inline void inv_fft(std::vector<Tp> &a) {
inv_fft_n(a.begin(), a.size());
}
template <typename Tp>
inline std::vector<Tp> convolution_fft(std::vector<Tp> a, std::vector<Tp> b) {
if (a.empty() || b.empty()) return {};
const int n = a.size();
const int m = b.size();
const int len = fft_len(n + m - 1);
a.resize(len);
b.resize(len);
fft(a);
fft(b);
for (int i = 0; i < len; ++i) a[i] *= b[i];
inv_fft(a);
a.resize(n + m - 1);
return a;
}
template <typename Tp>
inline std::vector<Tp> square_fft(std::vector<Tp> a) {
if (a.empty()) return {};
const int n = a.size();
const int len = fft_len(n * 2 - 1);
a.resize(len);
fft(a);
for (int i = 0; i < len; ++i) a[i] *= a[i];
inv_fft(a);
a.resize(n * 2 - 1);
return a;
}
template <typename Tp>
inline std::vector<Tp> convolution_naive(const std::vector<Tp> &a, const std::vector<Tp> &b) {
if (a.empty() || b.empty()) return {};
const int n = a.size();
const int m = b.size();
std::vector<Tp> res(n + m - 1);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) res[i + j] += a[i] * b[j];
return res;
}
template <typename Tp>
inline std::vector<Tp> convolution(const std::vector<Tp> &a, const std::vector<Tp> &b) {
if (std::min(a.size(), b.size()) < 60) return convolution_naive(a, b);
if (std::addressof(a) == std::addressof(b)) return square_fft(a);
return convolution_fft(a, b);
}
#line 2 "fps_basic.hpp"
#line 2 "semi_relaxed_conv.hpp"
#line 5 "semi_relaxed_conv.hpp"
#include <type_traits>
#include <utility>
#line 8 "semi_relaxed_conv.hpp"
// returns coefficients generated by closure
// closure: gen(index, current_product)
template <typename Tp, typename Closure>
inline std::enable_if_t<std::is_invocable_r_v<Tp, Closure, int, const std::vector<Tp> &>,
std::vector<Tp>>
semi_relaxed_convolution(const std::vector<Tp> &A, Closure gen, int n) {
enum { BaseCaseSize = 32 };
static_assert((BaseCaseSize & (BaseCaseSize - 1)) == 0);
static const int Block[] = {16, 16, 16, 16, 16};
static const int BlockSize[] = {
BaseCaseSize,
BaseCaseSize * Block[0],
BaseCaseSize * Block[0] * Block[1],
BaseCaseSize * Block[0] * Block[1] * Block[2],
BaseCaseSize * Block[0] * Block[1] * Block[2] * Block[3],
BaseCaseSize * Block[0] * Block[1] * Block[2] * Block[3] * Block[4],
};
// returns (which_block, level)
auto blockinfo = [](int ind) {
int i = ind / BaseCaseSize, lv = 0;
while ((i & (Block[lv] - 1)) == 0) i /= Block[lv++];
return std::make_pair(i & (Block[lv] - 1), lv);
};
std::vector<Tp> B(n), AB(n);
std::vector<std::vector<std::vector<Tp>>> dftA, dftB;
for (int i = 0; i < n; ++i) {
const int s = i & (BaseCaseSize - 1);
// blocked contribution
if (i >= BaseCaseSize && s == 0) {
const auto [j, lv] = blockinfo(i);
const int blocksize = BlockSize[lv];
if (blocksize * j == i) {
if ((int)dftA.size() == lv) {
dftA.emplace_back();
dftB.emplace_back(Block[lv] - 1);
}
if ((j - 1) * blocksize < (int)A.size()) {
dftA[lv]
.emplace_back(A.begin() + (j - 1) * blocksize,
A.begin() + std::min((j + 1) * blocksize, (int)A.size()))
.resize(blocksize * 2);
fft(dftA[lv][j - 1]);
} else {
dftA[lv].emplace_back(blocksize * 2);
}
}
dftB[lv][j - 1].resize(blocksize * 2);
std::copy_n(B.begin() + (i - blocksize), blocksize, dftB[lv][j - 1].begin());
std::fill_n(dftB[lv][j - 1].begin() + blocksize, blocksize, Tp());
fft(dftB[lv][j - 1]);
// middle product
std::vector<Tp> mp(blocksize * 2);
for (int k = 0; k < j; ++k)
for (int l = 0; l < blocksize * 2; ++l)
mp[l] += dftA[lv][j - 1 - k][l] * dftB[lv][k][l];
inv_fft(mp);
for (int k = 0; k < blocksize && i + k < n; ++k) AB[i + k] += mp[k + blocksize];
}
// basecase contribution
for (int j = std::max(i - s, i - (int)A.size() + 1); j < i; ++j) AB[i] += A[i - j] * B[j];
B[i] = gen(i, AB);
if (!A.empty()) AB[i] += A[0] * B[i];
}
return B;
}
#line 7 "fps_basic.hpp"
template <typename Tp>
inline int order(const std::vector<Tp> &a) {
for (int i = 0; i < (int)a.size(); ++i)
if (a[i] != 0) return i;
return -1;
}
template <typename Tp>
inline std::vector<Tp> inv(const std::vector<Tp> &a, int n) {
assert(!a.empty());
if (n <= 0) return {};
return semi_relaxed_convolution(
a, [v = a[0].inv()](int n, auto &&c) { return n == 0 ? v : -c[n] * v; }, n);
}
template <typename Tp>
inline std::vector<Tp> div(const std::vector<Tp> &a, const std::vector<Tp> &b, int n) {
assert(!b.empty());
if (n <= 0) return {};
return semi_relaxed_convolution(
b,
[&, v = b[0].inv()](int n, auto &&c) {
if (n < (int)a.size()) return (a[n] - c[n]) * v;
return -c[n] * v;
},
n);
}
template <typename Tp>
inline std::vector<Tp> deriv(const std::vector<Tp> &a) {
const int n = (int)a.size() - 1;
if (n <= 0) return {};
std::vector<Tp> res(n);
for (int i = 1; i <= n; ++i) res[i - 1] = a[i] * i;
return res;
}
template <typename Tp>
inline std::vector<Tp> integr(const std::vector<Tp> &a, Tp c = {}) {
const int n = a.size() + 1;
auto &&bin = Binomial<Tp>::get(n);
std::vector<Tp> res(n);
res[0] = c;
for (int i = 1; i < n; ++i) res[i] = a[i - 1] * bin.inv(i);
return res;
}
template <typename Tp>
inline std::vector<Tp> log(const std::vector<Tp> &a, int n) {
return integr(div(deriv(a), a, n - 1));
}
template <typename Tp>
inline std::vector<Tp> exp(const std::vector<Tp> &a, int n) {
if (n <= 0) return {};
assert(!a.empty() && a[0] == 0);
return semi_relaxed_convolution(
deriv(a),
[bin = Binomial<Tp>::get(n)](int n, auto &&c) {
return n == 0 ? Tp(1) : c[n - 1] * bin.inv(n);
},
n);
}
template <typename Tp>
inline std::vector<Tp> pow(std::vector<Tp> a, long long e, int n) {
if (n <= 0) return {};
if (e == 0) {
std::vector<Tp> res(n);
res[0] = 1;
return res;
}
const int o = order(a);
if (o < 0 || o > n / e || (o == n / e && n % e == 0)) return std::vector<Tp>(n);
if (o != 0) a.erase(a.begin(), a.begin() + o);
const Tp ia0 = a[0].inv();
const Tp a0e = a[0].pow(e);
const Tp me = e;
for (int i = 0; i < (int)a.size(); ++i) a[i] *= ia0;
a = log(a, n - o * e);
for (int i = 0; i < (int)a.size(); ++i) a[i] *= me;
a = exp(a, n - o * e);
for (int i = 0; i < (int)a.size(); ++i) a[i] *= a0e;
a.insert(a.begin(), o * e, Tp());
return a;
}
#line 9 "fps_composition.hpp"
// returns f(g) mod x^n
// see: https://arxiv.org/abs/2404.05177
// Yasunori Kinoshita, Baitian Li. Power Series Composition in Near-Linear Time.
template <typename Tp>
inline std::vector<Tp> composition(const std::vector<Tp> &f, const std::vector<Tp> &g, int n) {
if (n <= 0) return {};
if (g.empty()) {
std::vector<Tp> res(n);
if (!f.empty()) res[0] = f[0];
return res;
}
// [y^(-1)] (f(y) / (-g(x) + y)) mod x^n
// R[x]((y^(-1)))
auto rec = [g0 = g[0]](auto &&rec, const std::vector<Tp> &P, const std::vector<Tp> &Q, int d,
int n) {
if (n == 1) {
std::vector<Tp> invQ(d + 1);
auto &&bin = Binomial<Tp>::get(d * 2);
Tp gg = 1;
for (int i = 0; i <= d; ++i) invQ[d - i] = bin.binom(d + i - 1, d - 1) * gg, gg *= g0;
// invQ[i] = [y^(-2d + i)]Q
// P[0,d-1] * invQ[-2d,-d] => [0,d-1] * [0,d]
// take [-d,-1] => take [d,2d-1]
auto PinvQ = convolution(P, invQ);
PinvQ.erase(PinvQ.begin(), PinvQ.begin() + d);
PinvQ.resize(d);
return PinvQ;
}
std::vector<Tp> dftQ(d * n * 4);
for (int i = 0; i < d; ++i)
for (int j = 0; j < n; ++j) dftQ[i * (n * 2) + j] = Q[i * n + j];
dftQ[d * n * 2] = 1;
fft(dftQ);
std::vector<Tp> V(d * n * 2);
for (int i = 0; i < d * n * 4; i += 2) V[i / 2] = dftQ[i] * dftQ[i + 1];
inv_fft(V);
V[0] -= 1;
for (int i = 1; i < d * 2; ++i)
for (int j = 0; j < n / 2; ++j) V[i * (n / 2) + j] = V[i * n + j];
V.resize(d * n);
const auto T = rec(rec, P, V, d * 2, n / 2);
std::vector<Tp> dftT(d * n * 2);
for (int i = 0; i < d * 2; ++i)
for (int j = 0; j < n / 2; ++j) dftT[i * n + j] = T[i * (n / 2) + j];
fft(dftT);
std::vector<Tp> U(d * n * 4);
for (int i = 0; i < d * n * 4; i += 2) {
U[i] = dftT[i / 2] * dftQ[i + 1];
U[i + 1] = dftT[i / 2] * dftQ[i];
}
inv_fft(U);
// [-2d,d-1] => [0,3d-1]
// take [-d,-1] => take [d,2d-1]
for (int i = 0; i < d; ++i)
for (int j = 0; j < n; ++j) U[i * n + j] = U[(i + d) * (n * 2) + j];
U.resize(d * n);
return U;
};
int k = 1;
while (k < std::max(n, (int)f.size())) k *= 2;
std::vector<Tp> Q(k);
for (int i = 0; i < std::min(k, (int)g.size()); ++i) Q[i] = -g[i];
auto res = rec(rec, f, Q, 1, k);
res.resize(n);
return res;
}
// returns [x^k]gf^0, [x^k]gf, ..., [x^k]gf^(n-1)
// see: https://noshi91.hatenablog.com/entry/2024/03/16/224034
// noshi91. FPS の合成と逆関数、冪乗の係数列挙 Θ(n (log(n))^2)
template <typename Tp>
inline std::vector<Tp> enum_kth_term_of_power(const std::vector<Tp> &f, const std::vector<Tp> &g,
int k, int n) {
if (k < 0 || n <= 0) return {};
if (f.empty()) {
std::vector<Tp> res(n);
if (k < (int)g.size()) res[0] = g[k];
return res;
}
// [x^k] (g(x) / (-f(x) + y))
// R[x]((y^(-1)))
std::vector<Tp> P(g), Q(k + 1);
P.resize(k + 1);
for (int i = 0; i < std::min(k + 1, (int)f.size()); ++i) Q[i] = -f[i];
int d = 1;
for (; k; d *= 2, k /= 2) {
const int len = fft_len((d * 2) * ((k + 1) * 2) - 1);
std::vector<Tp> dftP(len), dftQ(len);
for (int i = 0; i < d; ++i)
for (int j = 0; j <= k; ++j) {
dftP[i * ((k + 1) * 2) + j] = P[i * (k + 1) + j];
dftQ[i * ((k + 1) * 2) + j] = Q[i * (k + 1) + j];
}
dftQ[d * (k + 1) * 2] = 1;
fft(dftP);
fft(dftQ);
P.resize(len / 2);
Q.resize(len / 2);
if (k & 1) {
auto &&root = FftInfo<Tp>::get().inv_root(len / 2);
for (int i = 0; i < len; i += 2) {
P[i / 2] = (dftP[i] * dftQ[i + 1] - dftP[i + 1] * dftQ[i]).div_by_2() * root[i / 2];
Q[i / 2] = dftQ[i] * dftQ[i + 1];
}
} else {
for (int i = 0; i < len; i += 2) {
P[i / 2] = (dftP[i] * dftQ[i + 1] + dftP[i + 1] * dftQ[i]).div_by_2();
Q[i / 2] = dftQ[i] * dftQ[i + 1];
}
}
inv_fft(P);
inv_fft(Q);
if (d * (k + 1) * 4 >= len) Q[(d * (k + 1) * 4) % len] -= 1;
for (int i = 1; i < d * 2; ++i)
for (int j = 0; j <= k / 2; ++j) {
P[i * (k / 2 + 1) + j] = P[i * (k + 1) + j];
Q[i * (k / 2 + 1) + j] = Q[i * (k + 1) + j];
}
P.resize(d * 2 * (k / 2 + 1));
Q.resize(d * 2 * (k / 2 + 1));
}
std::vector<Tp> invQ(n + 1);
auto &&bin = Binomial<Tp>::get(d + n);
Tp ff = 1;
for (int i = 0; i <= n; ++i) invQ[n - i] = bin.binom(d + i - 1, d - 1) * ff, ff *= f[0];
// invQ[i] = [y^(-2d + i)]Q
// P[0,d-1] * invQ[-(d+n),-d] => [0,d-1] * [0,n]
auto PinvQ = convolution(P, invQ);
// take [-n,-1] => take [d,d+n-1]
PinvQ.erase(PinvQ.begin(), PinvQ.begin() + d);
PinvQ.resize(n);
// output => [-1,-n] reverse
// before I just reverse it and mistaken something.
std::reverse(PinvQ.begin(), PinvQ.end());
return PinvQ;
}
// returns g s.t. f(g) = g(f) = x mod x^n
template <typename Tp>
inline std::vector<Tp> reversion(std::vector<Tp> f, int n) {
if (n <= 0 || f.size() < 2) return {};
assert(f[1] != 0);
const auto if1 = f[1].inv();
if (n == 1) return {Tp()};
f.resize(n);
Tp ff = 1;
for (int i = 1; i < n; ++i) f[i] *= ff *= if1;
auto a = enum_kth_term_of_power(f, {Tp(1)}, n - 1, n);
auto &&bin = Binomial<Tp>::get(n);
for (int i = 1; i < n; ++i) a[i] *= (n - 1) * bin.inv(i);
auto b = pow(std::vector(a.rbegin(), a.rend() - 1), Tp(1 - n).inv().val(), n - 1);
for (int i = 0; i < n - 1; ++i) b[i] *= if1;
b.insert(b.begin(), Tp());
return b;
}
#line 2 "modint.hpp"
#include <iostream>
#line 5 "modint.hpp"
template <unsigned Mod>
class ModInt {
static_assert((Mod >> 31) == 0, "`Mod` must less than 2^(31)");
template <typename Int>
static std::enable_if_t<std::is_integral_v<Int>, unsigned> safe_mod(Int v) {
using D = std::common_type_t<Int, unsigned>;
return (v %= (int)Mod) < 0 ? (D)(v + (int)Mod) : (D)v;
}
struct PrivateConstructor {};
static inline PrivateConstructor private_constructor{};
ModInt(PrivateConstructor, unsigned v) : v_(v) {}
unsigned v_;
public:
static unsigned mod() { return Mod; }
static ModInt from_raw(unsigned v) { return ModInt(private_constructor, v); }
ModInt() : v_() {}
template <typename Int, typename std::enable_if_t<std::is_signed_v<Int>, int> = 0>
ModInt(Int v) : v_(safe_mod(v)) {}
template <typename Int, typename std::enable_if_t<std::is_unsigned_v<Int>, int> = 0>
ModInt(Int v) : v_(v % Mod) {}
unsigned val() const { return v_; }
ModInt operator-() const { return from_raw(v_ == 0 ? v_ : Mod - v_); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
for (ModInt x(*this), res(from_raw(1));; x *= x) {
if (e & 1) res *= x;
if ((e >>= 1) == 0) return res;
}
}
ModInt inv() const {
int x1 = 1, x3 = 0, a = val(), b = Mod;
while (b) {
int q = a / b, x1_old = x1, a_old = a;
x1 = x3, x3 = x1_old - x3 * q, a = b, b = a_old - b * q;
}
return from_raw(x1 < 0 ? x1 + (int)Mod : x1);
}
template <bool Odd = (Mod & 1)>
std::enable_if_t<Odd, ModInt> div_by_2() const {
if (v_ & 1) return from_raw((v_ + Mod) >> 1);
return from_raw(v_ >> 1);
}
ModInt &operator+=(const ModInt &a) {
if ((v_ += a.v_) >= Mod) v_ -= Mod;
return *this;
}
ModInt &operator-=(const ModInt &a) {
if ((v_ += Mod - a.v_) >= Mod) v_ -= Mod;
return *this;
}
ModInt &operator*=(const ModInt &a) {
v_ = (unsigned long long)v_ * a.v_ % Mod;
return *this;
}
ModInt &operator/=(const ModInt &a) { return *this *= a.inv(); }
friend ModInt operator+(const ModInt &a, const ModInt &b) { return ModInt(a) += b; }
friend ModInt operator-(const ModInt &a, const ModInt &b) { return ModInt(a) -= b; }
friend ModInt operator*(const ModInt &a, const ModInt &b) { return ModInt(a) *= b; }
friend ModInt operator/(const ModInt &a, const ModInt &b) { return ModInt(a) /= b; }
friend bool operator==(const ModInt &a, const ModInt &b) { return a.v_ == b.v_; }
friend bool operator!=(const ModInt &a, const ModInt &b) { return a.v_ != b.v_; }
friend std::istream &operator>>(std::istream &a, ModInt &b) {
int v;
a >> v;
b.v_ = safe_mod(v);
return a;
}
friend std::ostream &operator<<(std::ostream &a, const ModInt &b) { return a << b.val(); }
};
#line 7 "test/compositional_inverse_of_formal_power_series_large.0.test.cpp"
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
using mint = ModInt<998244353>;
int n;
std::cin >> n;
std::vector<mint> f(n);
for (int i = 0; i < n; ++i) std::cin >> f[i];
const auto g = reversion(f, n);
for (int i = 0; i < n; ++i) std::cout << g[i] << ' ';
return 0;
}
/*#line 1 "test/compositional_inverse_of_formal_power_series_large.0.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/compositional_inverse_of_formal_power_series_large"
#line 2 "fps_composition.hpp"
#line 2 "binomial.hpp"
#include <algorithm>
#include <vector>
template <typename Tp>
class Binomial {
std::vector<Tp> factorial_, invfactorial_;
Binomial() : factorial_{Tp(1)}, invfactorial_{Tp(1)} {}
void preprocess(int n) {
if (const int nn = factorial_.size(); nn < n) {
int k = nn;
while (k < n) k *= 2;
k = std::min<long long>(k, Tp::mod());
factorial_.resize(k);
invfactorial_.resize(k);
for (int i = nn; i < k; ++i) factorial_[i] = factorial_[i - 1] * i;
invfactorial_.back() = factorial_.back().inv();
for (int i = k - 2; i >= nn; --i) invfactorial_[i] = invfactorial_[i + 1] * (i + 1);
}
}
public:
static const Binomial &get(int n) {
static Binomial bin;
bin.preprocess(n);
return bin;
}
Tp binom(int n, int m) const {
return n < m ? Tp() : factorial_[n] * invfactorial_[m] * invfactorial_[n - m];
}
Tp inv(int n) const { return factorial_[n - 1] * invfactorial_[n]; }
Tp factorial(int n) const { return factorial_[n]; }
Tp inv_factorial(int n) const { return invfactorial_[n]; }
};
#line 2 "fft.hpp"
#line 4 "fft.hpp"
#include <cassert>
#include <iterator>
#include <memory>
#line 8 "fft.hpp"
template <typename Tp>
class FftInfo {
static Tp least_quadratic_nonresidue() {
for (int i = 2;; ++i)
if (Tp(i).pow((Tp::mod() - 1) / 2) == -1) return Tp(i);
}
const int ordlog2_;
const Tp zeta_;
const Tp invzeta_;
const Tp imag_;
const Tp invimag_;
mutable std::vector<Tp> root_;
mutable std::vector<Tp> invroot_;
FftInfo()
: ordlog2_(__builtin_ctzll(Tp::mod() - 1)),
zeta_(least_quadratic_nonresidue().pow((Tp::mod() - 1) >> ordlog2_)),
invzeta_(zeta_.inv()), imag_(zeta_.pow(1LL << (ordlog2_ - 2))), invimag_(-imag_),
root_{Tp(1), imag_}, invroot_{Tp(1), invimag_} {}
public:
static const FftInfo &get() {
static FftInfo info;
return info;
}
Tp imag() const { return imag_; }
Tp inv_imag() const { return invimag_; }
Tp zeta() const { return zeta_; }
Tp inv_zeta() const { return invzeta_; }
const std::vector<Tp> &root(int n) const {
// [0, n)
assert((n & (n - 1)) == 0);
if (const int s = root_.size(); s < n) {
root_.resize(n);
for (int i = __builtin_ctz(s); (1 << i) < n; ++i) {
const int j = 1 << i;
root_[j] = zeta_.pow(1LL << (ordlog2_ - i - 2));
for (int k = j + 1; k < j * 2; ++k) root_[k] = root_[k - j] * root_[j];
}
}
return root_;
}
const std::vector<Tp> &inv_root(int n) const {
// [0, n)
assert((n & (n - 1)) == 0);
if (const int s = invroot_.size(); s < n) {
invroot_.resize(n);
for (int i = __builtin_ctz(s); (1 << i) < n; ++i) {
const int j = 1 << i;
invroot_[j] = invzeta_.pow(1LL << (ordlog2_ - i - 2));
for (int k = j + 1; k < j * 2; ++k) invroot_[k] = invroot_[k - j] * invroot_[j];
}
}
return invroot_;
}
};
inline int fft_len(int n) {
--n;
n |= n >> 1, n |= n >> 2, n |= n >> 4, n |= n >> 8;
return (n | n >> 16) + 1;
}
template <typename Iterator>
inline void fft_n(Iterator a, int n) {
using Tp = typename std::iterator_traits<Iterator>::value_type;
assert((n & (n - 1)) == 0);
for (int j = 0; j < n / 2; ++j) {
auto u = a[j], v = a[j + n / 2];
a[j] = u + v, a[j + n / 2] = u - v;
}
auto &&root = FftInfo<Tp>::get().root(n / 2);
for (int i = n / 2; i >= 2; i /= 2) {
for (int j = 0; j < i / 2; ++j) {
auto u = a[j], v = a[j + i / 2];
a[j] = u + v, a[j + i / 2] = u - v;
}
for (int j = i, m = 1; j < n; j += i, ++m)
for (int k = j; k < j + i / 2; ++k) {
auto u = a[k], v = a[k + i / 2] * root[m];
a[k] = u + v, a[k + i / 2] = u - v;
}
}
}
template <typename Tp>
inline void fft(std::vector<Tp> &a) {
fft_n(a.begin(), a.size());
}
template <typename Iterator>
inline void inv_fft_n(Iterator a, int n) {
using Tp = typename std::iterator_traits<Iterator>::value_type;
assert((n & (n - 1)) == 0);
auto &&root = FftInfo<Tp>::get().inv_root(n / 2);
for (int i = 2; i < n; i *= 2) {
for (int j = 0; j < i / 2; ++j) {
auto u = a[j], v = a[j + i / 2];
a[j] = u + v, a[j + i / 2] = u - v;
}
for (int j = i, m = 1; j < n; j += i, ++m)
for (int k = j; k < j + i / 2; ++k) {
auto u = a[k], v = a[k + i / 2];
a[k] = u + v, a[k + i / 2] = (u - v) * root[m];
}
}
const Tp iv = Tp::mod() - Tp::mod() / n;
for (int j = 0; j < n / 2; ++j) {
auto u = a[j] * iv, v = a[j + n / 2] * iv;
a[j] = u + v, a[j + n / 2] = u - v;
}
}
template <typename Tp>
inline void inv_fft(std::vector<Tp> &a) {
inv_fft_n(a.begin(), a.size());
}
template <typename Tp>
inline std::vector<Tp> convolution_fft(std::vector<Tp> a, std::vector<Tp> b) {
if (a.empty() || b.empty()) return {};
const int n = a.size();
const int m = b.size();
const int len = fft_len(n + m - 1);
a.resize(len);
b.resize(len);
fft(a);
fft(b);
for (int i = 0; i < len; ++i) a[i] *= b[i];
inv_fft(a);
a.resize(n + m - 1);
return a;
}
template <typename Tp>
inline std::vector<Tp> square_fft(std::vector<Tp> a) {
if (a.empty()) return {};
const int n = a.size();
const int len = fft_len(n * 2 - 1);
a.resize(len);
fft(a);
for (int i = 0; i < len; ++i) a[i] *= a[i];
inv_fft(a);
a.resize(n * 2 - 1);
return a;
}
template <typename Tp>
inline std::vector<Tp> convolution_naive(const std::vector<Tp> &a, const std::vector<Tp> &b) {
if (a.empty() || b.empty()) return {};
const int n = a.size();
const int m = b.size();
std::vector<Tp> res(n + m - 1);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) res[i + j] += a[i] * b[j];
return res;
}
template <typename Tp>
inline std::vector<Tp> convolution(const std::vector<Tp> &a, const std::vector<Tp> &b) {
if (std::min(a.size(), b.size()) < 60) return convolution_naive(a, b);
if (std::addressof(a) == std::addressof(b)) return square_fft(a);
return convolution_fft(a, b);
}
#line 2 "fps_basic.hpp"
#line 2 "semi_relaxed_conv.hpp"
#line 5 "semi_relaxed_conv.hpp"
#include <type_traits>
#include <utility>
#line 8 "semi_relaxed_conv.hpp"
// returns coefficients generated by closure
// closure: gen(index, current_product)
template <typename Tp, typename Closure>
inline std::enable_if_t<std::is_invocable_r_v<Tp, Closure, int, const std::vector<Tp> &>,
std::vector<Tp>>
semi_relaxed_convolution(const std::vector<Tp> &A, Closure gen, int n) {
enum { BaseCaseSize = 32 };
static_assert((BaseCaseSize & (BaseCaseSize - 1)) == 0);
static const int Block[] = {16, 16, 16, 16, 16};
static const int BlockSize[] = {
BaseCaseSize,
BaseCaseSize * Block[0],
BaseCaseSize * Block[0] * Block[1],
BaseCaseSize * Block[0] * Block[1] * Block[2],
BaseCaseSize * Block[0] * Block[1] * Block[2] * Block[3],
BaseCaseSize * Block[0] * Block[1] * Block[2] * Block[3] * Block[4],
};
// returns (which_block, level)
auto blockinfo = [](int ind) {
int i = ind / BaseCaseSize, lv = 0;
while ((i & (Block[lv] - 1)) == 0) i /= Block[lv++];
return std::make_pair(i & (Block[lv] - 1), lv);
};
std::vector<Tp> B(n), AB(n);
std::vector<std::vector<std::vector<Tp>>> dftA, dftB;
for (int i = 0; i < n; ++i) {
const int s = i & (BaseCaseSize - 1);
// blocked contribution
if (i >= BaseCaseSize && s == 0) {
const auto [j, lv] = blockinfo(i);
const int blocksize = BlockSize[lv];
if (blocksize * j == i) {
if ((int)dftA.size() == lv) {
dftA.emplace_back();
dftB.emplace_back(Block[lv] - 1);
}
if ((j - 1) * blocksize < (int)A.size()) {
dftA[lv]
.emplace_back(A.begin() + (j - 1) * blocksize,
A.begin() + std::min((j + 1) * blocksize, (int)A.size()))
.resize(blocksize * 2);
fft(dftA[lv][j - 1]);
} else {
dftA[lv].emplace_back(blocksize * 2);
}
}
dftB[lv][j - 1].resize(blocksize * 2);
std::copy_n(B.begin() + (i - blocksize), blocksize, dftB[lv][j - 1].begin());
std::fill_n(dftB[lv][j - 1].begin() + blocksize, blocksize, Tp());
fft(dftB[lv][j - 1]);
// middle product
std::vector<Tp> mp(blocksize * 2);
for (int k = 0; k < j; ++k)
for (int l = 0; l < blocksize * 2; ++l)
mp[l] += dftA[lv][j - 1 - k][l] * dftB[lv][k][l];
inv_fft(mp);
for (int k = 0; k < blocksize && i + k < n; ++k) AB[i + k] += mp[k + blocksize];
}
// basecase contribution
for (int j = std::max(i - s, i - (int)A.size() + 1); j < i; ++j) AB[i] += A[i - j] * B[j];
B[i] = gen(i, AB);
if (!A.empty()) AB[i] += A[0] * B[i];
}
return B;
}
#line 7 "fps_basic.hpp"
template <typename Tp>
inline int order(const std::vector<Tp> &a) {
for (int i = 0; i < (int)a.size(); ++i)
if (a[i] != 0) return i;
return -1;
}
template <typename Tp>
inline std::vector<Tp> inv(const std::vector<Tp> &a, int n) {
assert(!a.empty());
if (n <= 0) return {};
return semi_relaxed_convolution(
a, [v = a[0].inv()](int n, auto &&c) { return n == 0 ? v : -c[n] *
}*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 3524kb
input:
10 0 482489159 284392228 175130719 106560389 524766645 688673066 704125885 103606190 744337759
output:
0 403565917 722348898 212373570 70344818 552960467 627234437 521499134 749213359 527708013
result:
ok 10 numbers
Test #2:
score: 1
Accepted
time: 0ms
memory: 3604kb
input:
7 0 67723255 963748660 450953230 692314616 881897597 514354565
output:
0 463521861 789917981 241619069 614032541 389515910 287070433
result:
ok 7 numbers
Test #3:
score: 1
Accepted
time: 0ms
memory: 3628kb
input:
5 0 421312558 393838585 0 0
output:
0 7288836 523801396 123359649 983069534
result:
ok 5 number(s): "0 7288836 523801396 123359649 983069534"
Test #4:
score: 1
Accepted
time: 0ms
memory: 3572kb
input:
10 0 801878424 341342216 941798983 984836848 353869485 962101344 493428223 408956490 449562621
output:
0 387089923 872325296 890930829 103170501 343666664 227474888 984491691 410312427 952874418
result:
ok 10 numbers
Test #5:
score: 1
Accepted
time: 0ms
memory: 3632kb
input:
9 0 598468320 644453085 494305366 629585356 241251239 353077090 285526227 504587856
output:
0 124097070 263818072 530512145 612083778 891229246 386703541 848843206 787008182
result:
ok 9 numbers
Subtask #2:
score: 1
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 1
Accepted
time: 2ms
memory: 4000kb
input:
997 0 968319609 509860895 153515242 600756696 542768627 798866409 385818355 420946077 848827116 910394784 459460677 709888679 9530403 294892032 654097038 207202500 409309123 522776440 975506175 88876107 669381603 722740509 549393530 497060306 288411117 634087922 909331640 754393456 200677518 1611984...
output:
0 934142440 662194953 989223213 333166939 46525108 839821872 148595111 635585457 13949441 147828538 93803320 412368226 941840091 841559911 792071754 684666095 837450133 187154480 728832113 190400411 18465971 188977178 456550469 273454749 281159729 954560558 725174428 984287710 863132378 457970341 61...
result:
ok 997 numbers
Test #7:
score: 1
Accepted
time: 2ms
memory: 3708kb
input:
996 0 343376890 102769591 584195155 493738676 903423994 997618982 432164648 569623303 777023137 938928191 982320914 48511790 446086547 457634250 476784356 408387060 56044740 625518122 493022802 295015975 587461279 420806714 900219263 521422309 604797831 127758873 655883342 36459995 628084663 2279260...
output:
0 610046618 923310701 473576498 242643450 604425119 870716402 29763465 225593941 898674727 810474884 673362 58778068 299759156 7608667 507797631 423816862 407454955 638713875 100455597 101715449 241303974 151704642 205063964 383052445 485026175 590544505 944202856 562733668 382985916 579573499 97092...
result:
ok 996 numbers
Test #8:
score: 1
Accepted
time: 2ms
memory: 3704kb
input:
998 0 426727698 0 15604032 535570299 646260380 65982964 878366540 0 483759262 821784857 0 0 210627770 0 0 398387211 0 530011358 144730461 88692974 0 0 0 306183169 0 0 139296312 331419517 0 764893071 70056120 335720216 601196174 842723536 47469344 253514001 0 158822334 0 338061633 0 657406579 3168350...
output:
0 665890480 0 653173226 219894443 617644225 293264450 725384586 978998855 653486899 748172993 148448011 904711088 333170692 556022353 835118394 692177611 772760727 296639357 632577737 588107841 811145081 138554291 834737530 40548053 342166235 766276178 146695328 927470674 837667085 216292198 1729931...
result:
ok 998 numbers
Test #9:
score: 1
Accepted
time: 2ms
memory: 3752kb
input:
998 0 489693425 265084187 698012574 771306095 391413405 476076652 347567482 554594725 152576930 180724631 250869925 197660145 660684107 845040665 270057155 164096794 592411882 950908957 886527128 618482499 487905342 170560185 884330287 111888373 170569656 570591145 600290429 876919780 769810482 4694...
output:
0 682223983 490241581 812026825 295044971 101302222 944166700 949694819 539107896 293601563 621267734 77029035 446807283 747081403 722818871 158617062 676313154 731432024 201007678 307426873 575365262 326036816 119139118 806589026 669340006 687419624 130958270 987132107 654482768 296518568 424772753...
result:
ok 998 numbers
Test #10:
score: 1
Accepted
time: 2ms
memory: 3932kb
input:
1000 0 664564139 406922557 976480332 635941105 379827055 280282511 981622877 379929911 994923629 664793246 303907334 13837744 356744373 549270882 150702198 181765521 3019770 932002787 646642365 737346718 327232923 385928331 434050032 719438478 2101905 164601268 258488988 476909337 324936975 22999863...
output:
0 552143786 761342934 717745684 822668616 97326581 335913756 812315876 109128869 319376547 244840876 780790937 490933868 988185599 819146952 886989582 963515634 187304358 15108977 899828850 297534264 722357102 702518988 952483021 884250953 937802982 884668898 441283413 70700852 531062759 33516438 62...
result:
ok 1000 numbers
Subtask #3:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 1
Accepted
time: 5ms
memory: 3800kb
input:
1997 0 685183886 579079874 968503536 195860044 153330993 918416932 535084982 745990387 399748400 162388638 808320325 180886911 397309509 216418046 319198312 349438003 141596877 254822443 252158341 663124362 718635588 927200614 399935085 21169885 915884845 660270181 262636228 994770254 852325473 9017...
output:
0 428816988 696860837 837565504 197447424 642096292 68783842 860447554 202809780 223322542 762568697 329119759 391868440 280333806 494761529 641416742 432084129 301664342 625368357 924852940 601238944 710303223 413714877 68876210 580652282 995437338 643977613 53853085 249507845 345488241 281348777 7...
result:
ok 1997 numbers
Test #12:
score: 1
Accepted
time: 2ms
memory: 4096kb
input:
2000 0 124099488 387009336 281376613 80816790 472340621 418342229 432324085 657740855 529408829 752476445 397438588 209604222 855877953 564629941 244821890 952372625 500542762 740784377 641164521 38620013 549410041 652511561 530198945 17617103 528217396 914504265 222676077 980986753 207779032 177719...
output:
0 831429995 764545387 93142402 720689657 439120295 808319414 316268973 312667414 416073284 703873172 221558347 82670922 41458437 244115473 153267780 839757906 697017790 849050261 13213124 603992565 420418966 926829161 609188295 263441717 437960360 18222829 191893514 602853904 295751479 958748025 956...
result:
ok 2000 numbers
Test #13:
score: 1
Accepted
time: 5ms
memory: 4020kb
input:
1997 0 209746029 0 40611169 970387530 0 0 0 0 0 992946798 0 0 955367110 0 0 0 0 538752156 0 276740355 476738384 595518855 434637990 0 663996114 698813951 161724196 0 0 672922325 0 188570740 0 631166892 60645694 0 37501601 7296453 448970082 138248519 739273969 0 441460697 801084136 81308290 8977152 7...
output:
0 372722143 0 892365184 157472137 966041124 356146560 817242801 391929701 665391953 356731041 119091702 147084774 796617441 245769999 923355339 957696572 31032114 538082110 553671435 110778110 783736669 986393336 925671933 334110154 669393422 399715800 553777972 309543158 263107289 232181855 9021076...
result:
ok 1997 numbers
Test #14:
score: 1
Accepted
time: 5ms
memory: 3792kb
input:
1996 0 222603514 52680703 994877972 648815254 236243939 266700003 932069799 322982293 909513007 117784588 343952427 794696099 582470055 864130762 185048458 140184719 395805795 804599571 218256446 707878940 438199174 46919990 48946686 105058131 919822918 811379407 370440670 389834339 967661435 911990...
output:
0 318977037 879652452 477185577 387131819 635499453 964900783 444234107 118651109 148961323 92553221 632657137 854767699 923935714 533344045 2320064 715107892 816644241 87532842 488281683 235505702 1995894 595377738 572841325 241039855 484206017 160302477 493432493 793550325 934660701 744435013 9738...
result:
ok 1996 numbers
Test #15:
score: 1
Accepted
time: 5ms
memory: 4104kb
input:
1996 0 914435946 731966111 748087835 201475658 857820621 812144870 475335839 228242555 844404536 261632152 133082691 334188322 427196877 184224668 677631169 588630478 112706344 146034045 779162059 893152563 366557561 991770192 483159400 186918807 30233796 637311678 304428112 788947665 174633174 7108...
output:
0 253924649 695312604 368049828 644761782 139224726 370746536 110438781 188683221 255244094 897979688 451714234 793829708 236464270 597685598 29867847 346734362 314365383 172694650 954560018 250492126 759454887 901303945 338128757 904749475 868213043 863494852 695607100 617616888 458145158 501461208...
result:
ok 1996 numbers
Subtask #4:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 1
Accepted
time: 10ms
memory: 4284kb
input:
3996 0 62756732 557525501 500152560 536867575 943307688 757910862 229314731 648479267 909564616 87868870 849097336 224676326 331340940 432834552 591042196 719598173 474522791 428418453 981244909 973601131 409696517 68108878 252229954 28872345 816225334 213583178 367818800 92815417 747866164 51260936...
output:
0 290739126 44180941 630281548 502729775 982197016 46974584 8289121 216092085 981249658 543589307 805180518 959816943 282072344 889983191 152439429 145940788 281243843 203760831 90579837 39754337 394476637 679676126 405594567 55067986 108642406 79770423 27788063 218458145 348486580 410820999 4934532...
result:
ok 3996 numbers
Test #17:
score: 1
Accepted
time: 10ms
memory: 4012kb
input:
3998 0 239768459 523166573 387991607 229278267 642448452 172569321 623879153 956043821 272981673 507916358 174583946 383548682 199826869 443041143 493426166 290939874 309811049 800571105 193749506 584656257 919268539 943433590 108610603 500716681 516403717 668611514 703914880 234060577 946569122 958...
output:
0 492280878 565175743 523705173 793169364 512896702 190951005 717637909 887114698 594151869 729116541 235030325 985278157 118203577 1879646 430648883 987723891 147451243 548297222 757589020 486337831 786781684 736508891 666433731 767437006 154602450 150376824 717644837 338684070 20758913 142913625 2...
result:
ok 3998 numbers
Test #18:
score: 1
Accepted
time: 10ms
memory: 3984kb
input:
4000 0 990262363 784728715 0 48653967 661794470 0 0 761855953 0 488058298 0 806096107 599220192 0 0 350782943 106090546 660651509 0 932348800 0 0 325769216 433507093 873985641 637364549 592323817 596544869 0 791731947 576500187 0 0 519734314 820936952 0 141231662 0 0 0 0 0 0 0 544352502 0 307705901 ...
output:
0 124022449 370137895 646695328 247483662 577122650 260204752 191272848 473865171 176418754 433378360 964318657 183416144 361926209 333990969 99995251 602188684 681989610 721280608 825321580 296755220 956934909 122371610 786676216 548732205 531416788 809766633 409263683 770014522 134863829 403214015...
result:
ok 4000 numbers
Test #19:
score: 1
Accepted
time: 10ms
memory: 4000kb
input:
3996 0 211439350 853180827 920012514 221446345 822427295 428733276 678983398 879708095 442805484 451418507 228643259 447068770 122397201 395681807 698907010 18379137 763777976 783439003 68988362 517030006 757426258 960730022 74340886 282530925 20179244 803685505 791858278 783902983 943271398 6645719...
output:
0 316233882 463291215 389210872 625590305 974457260 139261992 522147303 492567001 40153852 805428937 921213818 124916295 97494661 216604085 948888670 904357978 264401205 355804109 81367315 424005429 183745098 893297589 783737674 174882447 246032001 729345771 569267889 30810622 108243087 644439386 47...
result:
ok 3996 numbers
Test #20:
score: 1
Accepted
time: 10ms
memory: 4020kb
input:
3998 0 861660425 178495165 534405937 647219498 53979446 906373810 857736018 749942607 191193878 830712635 242085593 389574943 958113576 874167106 675012572 246072352 79650223 142850806 273757699 161229643 694297458 259049524 54827 763682219 135151812 732506569 837996603 723186425 335497349 112887012...
output:
0 736311932 185101090 430146188 21352733 678637743 89180426 771623521 541044937 550873552 651244308 594704587 412250498 864621175 253842830 925964912 181798176 994158013 625654127 707494224 849772481 922592511 974453848 693983984 85980419 807015907 816696904 660539615 34859521 3736978 441097791 2071...
result:
ok 3998 numbers
Subtask #5:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 1
Accepted
time: 23ms
memory: 4404kb
input:
6996 0 648833046 373590860 177304722 884907483 219479322 187111957 947100467 547518093 137435215 818046593 159962385 778093152 660344727 261355738 867979465 671025981 562473011 833205795 549153691 297531523 657998150 544044104 205553050 776466305 970701245 870614285 496487021 879448778 473401445 935...
output:
0 575377182 642392483 328401592 308859679 621668697 422643363 850018903 496835183 958853996 648501450 777254327 954174347 593443386 114866814 661028390 668749290 116187865 650203064 613047777 330800019 284042620 130259494 68072114 13793670 405626734 501155649 227339686 637451342 867646510 213419575 ...
result:
ok 6996 numbers
Test #22:
score: 1
Accepted
time: 22ms
memory: 4336kb
input:
6998 0 71733047 226583996 639643323 95546912 922784610 511111467 513679421 247554079 215856527 400660640 275953074 939261729 169632215 896590020 130632460 788973399 964257933 479606084 744401319 943941554 612360191 919006827 315645133 140962416 583494302 830807545 32863860 853144901 223203937 748539...
output:
0 369477988 749485208 952172075 233135318 640367437 919686167 229681866 737084793 630098535 965074229 426128144 955854374 546719922 733372615 818941581 2507671 645875056 335309109 543522945 621905633 200506728 629199608 706236275 20767689 385850472 349016800 136669711 650036774 346247670 10859536 88...
result:
ok 6998 numbers
Test #23:
score: 1
Accepted
time: 22ms
memory: 4624kb
input:
7000 0 409399599 0 583277833 0 176262911 891896787 990889754 546706976 0 90892406 0 0 0 417191238 441917207 0 0 0 0 0 0 0 598773940 0 0 376340781 0 540553072 0 0 947056910 0 0 746134911 0 0 553840341 0 0 243587086 66769341 81640851 822612335 0 0 0 0 0 230470096 807408119 0 0 539731217 456987966 0 0 ...
output:
0 653781446 0 103485026 0 238793611 457763788 701310698 13825675 317582929 546087918 3795306 577482301 451796621 765995558 897279159 486120010 513799701 940234953 633048227 300007811 601970149 170424441 414386260 236159069 932885007 87151753 608291097 482325749 948514801 540135912 21402672 709486581...
result:
ok 7000 numbers
Test #24:
score: 1
Accepted
time: 18ms
memory: 4328kb
input:
6999 0 539709872 699306399 71797653 94911604 700896867 642741772 333867759 677720853 134919676 181711912 604530454 485419807 856768846 976815479 882622084 985900277 212772766 301836268 263362460 49567001 649953172 795098596 511504695 220972547 675891756 854763758 351530886 978461941 540206965 340620...
output:
0 835536509 359472053 981542167 419578370 134684386 233544866 609052055 446360923 390053516 132442013 187371717 551939784 583834583 527751541 460458057 71465123 48866157 108709039 237811597 913575599 930042884 682399727 426128239 83141961 863420710 635986486 934859770 285874182 607939155 234651713 5...
result:
ok 6999 numbers
Test #25:
score: 1
Accepted
time: 22ms
memory: 4388kb
input:
6996 0 918611323 506491294 336427641 493829955 457740219 481529030 680402730 86426146 187901281 760955514 540603745 447236723 541542115 70957421 952944889 476824155 166175140 273798732 741046256 163719033 172848020 794802895 595350826 481041570 358805295 782327795 34315004 560381040 550466608 590507...
output:
0 872932248 433369118 315680623 511433941 768770967 540550084 663139730 220444413 64815286 694828477 963226665 139272703 147342699 762620708 218795863 718545427 334126932 209297572 183525613 341005839 215609511 681931322 445675792 557085697 286376464 197906027 838869745 312397527 227309350 861493951...
result:
ok 6996 numbers
Subtask #6:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 1
Accepted
time: 42ms
memory: 4560kb
input:
9997 0 20595644 821349252 669562559 237124612 81576518 424529115 951962182 953029849 752367214 692527496 390991794 341328219 618863342 640342295 263085958 954712231 378445670 166704317 698914287 692461027 990715383 134552584 64562858 646514727 450350949 773296738 731381607 25704644 230292060 7009351...
output:
0 686303159 772381119 360295262 567746060 734090809 922717477 348917508 699488855 870998586 276041930 446318237 156328537 789251099 647746555 377081353 192835575 364598977 58905888 352724362 94938296 337635485 993349704 46646338 394806369 668470304 401473022 750548577 612942428 595875095 411298544 9...
result:
ok 9997 numbers
Test #27:
score: 1
Accepted
time: 51ms
memory: 4580kb
input:
9996 0 225855649 979486462 416992765 391797931 54716805 255467950 104292552 251448530 55399662 594325487 862420526 104971766 776602006 880735693 835009166 575281166 838437905 162399226 698318784 702160436 568909572 350265309 109105127 913042871 845190853 552826785 12144581 762978308 775497047 533158...
output:
0 82706381 380313181 900183157 178875165 14810860 963435209 58363926 665485961 807445472 428210594 95167994 796451546 662323597 974125299 144534548 290100326 368602031 825171402 711877759 370066848 930114209 647504015 487526025 449065811 156294661 472621396 241213636 213234940 627215293 205435202 34...
result:
ok 9996 numbers
Test #28:
score: 1
Accepted
time: 49ms
memory: 4812kb
input:
9995 0 236172788 0 0 0 603680253 368168998 0 0 0 456240536 0 0 352429390 497506995 857754066 701206174 969355733 0 0 537815016 497073529 888716552 0 0 0 633095207 387274332 170170652 0 790291212 0 0 731164908 103216449 0 0 181757082 596190496 128190693 206963190 523842527 754978950 0 0 455126019 217...
output:
0 131758850 0 0 0 499144450 400393866 0 0 753905787 293987969 156883830 0 524804088 645192969 382935193 78763243 509483549 758019989 540042299 35533996 679573529 583973364 812392891 854381680 358150742 739559588 816702007 346127901 100893882 4082573 439823947 402465841 751800219 497976123 722570743 ...
result:
ok 9995 numbers
Test #29:
score: 1
Accepted
time: 50ms
memory: 4568kb
input:
10000 0 44245861 650300672 217035181 707559151 564258816 401264798 793434473 360506062 810684683 362326252 768625224 66270699 234024001 707079634 169179254 820683920 733777920 26838286 919511645 787936432 771713095 879261355 214124749 519231156 432783358 336479228 961568372 150807696 784351554 57637...
output:
0 593088375 394086836 361086731 567555653 840865960 829858552 609979159 369747311 604589372 587011765 895784317 700119620 348599384 870257123 197494584 766939548 681484143 59373113 702341632 658847633 846053088 84719369 395624086 153395915 929850949 661494219 125073568 839416807 644340028 386047844 ...
result:
ok 10000 numbers
Test #30:
score: 1
Accepted
time: 49ms
memory: 4556kb
input:
9999 0 844573640 298432836 275132432 673698532 453840204 987579097 756375030 571701291 35627930 507935715 92095639 748042990 843429153 547834731 237766597 917908047 177519769 882983339 117723049 205100810 264293657 367861783 843445601 17730082 175931954 937868340 734059988 612390955 816773812 891540...
output:
0 492805694 673069558 450853602 15160831 252085049 95418331 885420150 641922435 893505262 597585185 393120709 483694161 810230514 722129068 749632730 207712261 311205826 671218284 787273515 847428024 543673583 655310359 811729194 353034934 924914759 584923589 485673025 816825807 172358192 554440584 ...
result:
ok 9999 numbers
Subtask #7:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Test #31:
score: 1
Accepted
time: 49ms
memory: 4884kb
input:
15000 0 942217174 264005048 140822954 785809300 605253307 517762985 259589364 24027037 702942772 913700892 265487071 24548547 985247026 123110978 990368083 153945923 420828539 476634256 386918494 796181087 23494850 938519147 637365198 895550976 234222512 289620106 352239387 672314288 878778491 34559...
output:
0 435194502 871718319 885382792 989813248 117146102 966306723 304083011 279828612 498760694 36561474 397974814 953950412 756328318 711184156 572696251 656228238 206164545 882919314 993073034 366419076 310980765 77651481 911645990 495833715 771357894 351769851 119598808 285090396 53705710 743988228 1...
result:
ok 15000 numbers
Test #32:
score: 1
Accepted
time: 51ms
memory: 5020kb
input:
14999 0 458778691 609893083 239737850 297572961 365663120 683481665 887380275 502566974 600072237 600333171 787427804 892101125 957636708 28019715 224316344 300766642 641392269 723322245 642103593 368448010 334481811 501307866 670620314 425485301 918006940 617885859 73058945 101936462 314454363 7261...
output:
0 167891926 7561084 279719246 151942820 250822920 939916920 215114833 752950051 843046553 794993982 262052498 577244187 605563312 566276919 347014141 311006767 838585730 494280923 175274260 166745289 533747491 708208878 613038260 365608797 834024475 766483533 961121448 166725658 853869445 560986390 ...
result:
ok 14999 numbers
Test #33:
score: 1
Accepted
time: 52ms
memory: 4736kb
input:
14998 0 397729928 0 0 0 0 117568309 594795519 0 0 0 0 0 0 0 0 765550685 54930190 0 0 899680179 732642794 751962734 0 664595900 864939643 0 907864118 0 0 572282002 705340031 924780988 667710442 520565160 331619644 0 449136521 293258452 0 3885599 229671026 699130563 940022472 0 0 0 657621943 0 0 77481...
output:
0 924772328 0 0 0 0 198096762 46709037 0 0 0 952939741 238684527 132702751 0 0 113263919 97826566 217655193 435881216 888462191 424418140 61074121 113711720 295326437 525804512 612625915 745124226 739739130 31498068 990551724 394156958 680982312 553465636 958981968 671404437 355944811 874478454 4321...
result:
ok 14998 numbers
Test #34:
score: 1
Accepted
time: 52ms
memory: 4776kb
input:
14999 0 797796306 131862929 771817171 506922082 59141324 504807188 373088593 570763025 893943941 134902570 600935342 18685170 723221318 706068845 237772003 372797134 752506360 938409539 701313971 94955414 670223948 895987852 219224778 727444554 75292068 650349850 17756333 324669323 98803235 21353826...
output:
0 615026365 381263923 823447041 355709771 546163756 152795144 196296664 121456856 661508042 456907426 241465384 82771283 376669109 82556804 731449012 355689338 663142912 275359673 61834538 403490705 430827021 130604376 676094999 712221525 633655770 314604730 215768691 995581446 148516400 194899307 4...
result:
ok 14999 numbers
Test #35:
score: 1
Accepted
time: 52ms
memory: 4660kb
input:
14998 0 209748865 959877141 374982077 637873882 895593736 4686285 21237299 804578819 323349831 660061446 505769007 655717478 212435314 94656914 167093243 822522510 47884289 393865883 399654694 534747165 490795082 26423238 704185611 530482548 184768612 306934273 70338842 973899839 497910675 348841464...
output:
0 113122200 361760185 278369372 568028149 291910193 20438389 536104560 931882023 649009985 474698353 112394964 438716486 89493619 888252390 228320118 231522985 538092925 508969670 580406309 306109047 737413077 590941128 373627241 669904859 437768919 228382862 442683962 392014988 997524521 476506956 ...
result:
ok 14998 numbers
Subtask #8:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Test #36:
score: 1
Accepted
time: 101ms
memory: 5896kb
input:
19999 0 382382671 162342098 739097772 295023970 381422128 73160295 982735270 185867013 600844767 215121085 963096836 934238095 240781441 857348186 855859105 105375942 80240190 800723316 691499596 174030335 350407417 271247108 983237186 91628145 742718737 286491507 15049061 159448643 463347612 519440...
output:
0 246196464 487615627 401344342 952210290 475265883 386180354 994434824 626194221 506661419 231583812 901087595 771233277 593778460 843080947 27176298 642804841 304121143 556433762 110335035 804605553 631849959 838906209 150128285 241115950 426929171 980348855 608292505 579430134 651517184 582049372...
result:
ok 19999 numbers
Test #37:
score: 1
Accepted
time: 113ms
memory: 6028kb
input:
19996 0 992161001 440793385 317933415 752502205 811631693 542530240 844254196 138559270 299051303 434740084 157921989 499206672 18477042 956380627 994036191 701583068 371627238 168562122 698534398 355439538 332208101 752892748 139876597 370524687 803997461 254646464 64618636 17691481 733531518 78554...
output:
0 355844905 880143086 38820401 854079849 960390725 71686959 699140761 33332310 835921133 304634966 755571868 367769963 732929622 406697817 598179128 458241860 997628660 832075303 440357126 107656466 491046406 801050506 756177530 225226569 362769172 918052384 346065078 411554694 849538195 659188816 4...
result:
ok 19996 numbers
Test #38:
score: 1
Accepted
time: 105ms
memory: 6060kb
input:
20000 0 656208907 0 0 0 386366365 458117906 0 143232477 0 0 194740697 789950636 735230807 964582719 0 698426095 483818186 647390929 0 341271387 0 686999545 654296587 582423292 678088932 0 0 427771165 0 0 962206454 0 0 562347466 0 704978266 683695147 0 0 538918430 0 0 152665600 673924183 259410052 0 ...
output:
0 946665238 0 0 0 403881609 786028389 0 30940449 723741846 257899016 336000137 97304637 531352745 48702680 672333502 270115246 942767609 685022312 721789245 749243883 960240842 411052539 836636285 696045750 63904075 315236887 881604583 989896693 610003538 396182077 20298434 225646324 648296905 49189...
result:
ok 20000 numbers
Test #39:
score: 1
Accepted
time: 109ms
memory: 5888kb
input:
19999 0 7352903 546831467 949281642 257401295 746761860 148486139 463353608 332676414 375707454 409475034 82269976 819676033 456344976 493981154 296814250 39577174 899207432 594371461 121477530 584874228 695187031 527931995 28352925 46786216 932363959 814506556 411733396 943829034 240757757 54324618...
output:
0 206692933 332176138 479981912 819988995 740933723 471947479 663210421 197100130 151597674 481508097 798540348 882775187 152902903 974307742 882651387 150082937 989218807 415481883 491867434 543340664 13900613 144579723 401752595 136660867 517378735 56461565 803788358 803034968 683628140 6690960 92...
result:
ok 19999 numbers
Test #40:
score: 1
Accepted
time: 107ms
memory: 5964kb
input:
19999 0 908056027 995031221 291825998 238147974 804953970 102083478 295215821 129433256 805090825 310120117 316814419 43323064 451714589 507813330 175030862 592913797 957701644 268763634 116467952 687298175 770491950 940534929 258356547 751200456 216353730 407748499 505638465 244449540 816584205 977...
output:
0 14790196 903398895 295206691 248341837 822739056 652467398 426245817 118486277 725159263 80331398 106385729 587224380 955228707 949764831 811996224 754415536 294761735 38721896 217950513 66549588 133684443 47688198 106984606 262248946 50405264 81774088 146192778 547555615 598975295 59311502 601471...
result:
ok 19999 numbers
Subtask #9:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 1
Accepted
time: 111ms
memory: 6300kb
input:
29997 0 96202029 548444916 393422388 204175498 160502989 978544246 448120263 625221379 786473773 962799482 356610912 380861158 446450531 395641706 894123415 123448655 453307248 667860069 10805149 223050108 869731373 199420030 969186610 866505127 371551535 977052669 716322905 430979884 829611556 3300...
output:
0 169205210 849647913 465250408 781897850 399455847 464658794 826777876 251903294 43736641 36770018 70447971 691346987 811568281 318853405 505498462 25113188 965864510 826047330 503790165 527240420 108007078 703590150 315022980 905715718 834699728 602547780 843028239 470367459 729261079 92189754 286...
result:
ok 29997 numbers
Test #42:
score: 1
Accepted
time: 114ms
memory: 6356kb
input:
29998 0 818457865 779683488 497808277 396947147 352131800 978550762 106789639 896642783 890554081 167352878 555034448 686322399 61965894 516772171 783873165 302107309 940349265 474764228 552944546 138660107 441922077 947247630 713363673 155090930 263603729 47583303 269256235 763926746 620396330 4290...
output:
0 364583488 613697147 572112779 928499140 490259877 218314346 846329004 101968045 782591724 804669562 626286875 542521880 568507403 596311760 789737664 234711911 331183220 546949488 672234336 574588541 109484096 38856101 17998809 981835308 709284749 85263725 365067694 909792994 285063989 769780782 7...
result:
ok 29998 numbers
Test #43:
score: 1
Accepted
time: 115ms
memory: 6308kb
input:
29999 0 592630563 668497876 505999642 694037290 0 99222918 0 300262864 304797087 0 227937174 0 0 0 0 0 545977118 184127718 0 0 703740869 0 0 0 0 0 0 489783982 0 622866674 0 0 628896310 0 494851499 0 0 0 0 410281985 912894886 282795109 856990756 450953098 0 185585756 790023238 299215625 719897221 136...
output:
0 58910281 542499638 928758551 10569621 903570775 942872665 552607169 396789972 261238806 487001453 640034826 54653706 354609031 20469225 231130631 502074328 580337795 848824284 582579733 565732656 356032643 365913221 835602980 670120569 487132377 146392356 222443881 524735555 858788922 423116072 40...
result:
ok 29999 numbers
Test #44:
score: 1
Accepted
time: 114ms
memory: 6296kb
input:
29995 0 943829054 496028451 416009027 685462402 389952268 932107683 255095737 275664237 817624768 839705662 19177836 71479567 835740543 840256360 490054509 592292030 301365408 610196534 9929746 661910192 451676881 520767610 94291651 580694017 664649151 137523033 552110062 570107369 192502778 8677595...
output:
0 230933330 974879229 977830638 3262864 464701129 796629732 746723601 609509692 906418284 318709286 191277034 149754358 348159783 617430714 259351631 687978275 596047877 459246498 408273360 982951040 41538326 805452584 497546352 289637063 177929857 86003115 258200426 830655109 534165239 214795520 89...
result:
ok 29995 numbers
Test #45:
score: 1
Accepted
time: 111ms
memory: 6284kb
input:
29998 0 893449375 829245706 834262533 753577078 366257203 306024087 428741708 901333505 215008859 730071279 338487524 506380742 436349830 980996153 501855549 310148282 717918569 504367951 494717430 269961017 568104084 269199841 328507758 72611357 265891841 602448757 89440486 598118901 910348845 3376...
output:
0 760658213 854153856 377204335 277534750 843863989 849281926 370058632 626227706 386643463 415362437 931152234 392268295 201336930 444965653 169423841 945650788 62639845 523297609 303227879 274925401 382425561 943570010 777281577 800541426 759761280 542573593 52070576 399754797 569529092 490809816 ...
result:
ok 29998 numbers
Subtask #10:
score: 1
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Dependency #8:
100%
Accepted
Dependency #9:
100%
Accepted
Test #46:
score: 1
Accepted
time: 242ms
memory: 8996kb
input:
49998 0 40030948 26642523 670085986 569730165 135937669 429618042 34480142 112036321 922154687 949912335 361918330 112883846 294361069 837160751 977784323 335818239 431092687 30216391 122468428 82154631 580946216 184331275 691293736 462637683 176107046 324207075 979227203 433833046 205035368 3811728...
output:
0 203500247 677803735 623317211 242980486 537835006 256053941 179518221 213411017 95677385 743003869 453674658 526087770 607676734 631895883 991530373 169239373 575913635 300971451 687402189 156382072 328957976 815271742 527004836 870958782 917882586 109199027 804449578 192315504 435143451 747512158...
result:
ok 49998 numbers
Test #47:
score: 1
Accepted
time: 238ms
memory: 9120kb
input:
49996 0 911661971 541404641 702503760 686874889 63871710 490228702 699187738 352009493 862583016 301583477 745146970 128662155 602135149 161435362 651835530 88822797 298640518 641482823 463806598 799210185 196085305 4463455 774540214 288814085 651199754 829392153 865459663 188305655 892911706 642887...
output:
0 342083175 605901861 645910828 676029885 747967077 888381399 857524718 245900311 202716554 828062857 562258743 688527479 186933906 277434249 484657751 213887276 58751862 501606676 436274506 840273757 295056024 8896265 485557454 864511555 602439945 395683026 131523774 937276144 22709628 435250727 30...
result:
ok 49996 numbers
Test #48:
score: 1
Accepted
time: 246ms
memory: 8900kb
input:
49997 0 97207354 76726620 303440545 0 0 83366184 0 156844676 0 747673936 311968179 0 429885762 0 627044731 0 0 871617522 783445572 0 0 351823658 0 60663249 0 0 420311174 723054985 797795620 952660827 0 418798679 0 0 564483618 56196547 394308665 0 228736623 347244390 0 803854658 0 0 71581927 62865035...
output:
0 204765597 453548043 641344502 540899364 733584399 55853524 397294260 749155115 247481786 883093053 507233001 817444493 336287672 720370302 224656487 793567224 663746744 965500447 982898948 233892827 747587734 810278039 176656033 880139981 836204264 442421815 122482890 964476947 425071553 790232245...
result:
ok 49997 numbers
Test #49:
score: 1
Accepted
time: 246ms
memory: 8960kb
input:
49995 0 313510380 957039022 614489494 863563742 815513879 398966379 898856962 188112989 250560426 443757026 555704186 344893530 523403823 639225905 916979571 353302147 715202925 278218484 863531533 885726111 996136258 404371128 78982501 590588968 315691444 39955613 7070024 525928067 745551453 928539...
output:
0 247814833 96828163 451623828 204318765 934346162 450222270 158469165 902495085 947421057 754333651 723325045 39315395 369228055 516068474 29885270 86239422 128468992 87510011 22909047 39011794 708298511 600871503 390831633 246735483 669671153 222987636 745811027 453273303 938254187 866751990 36538...
result:
ok 49995 numbers
Test #50:
score: 1
Accepted
time: 242ms
memory: 8996kb
input:
49998 0 929524500 358725518 553447917 88443385 285234851 328852575 590506854 519767463 582873865 681152605 446713868 528495321 303245615 632500745 490242965 624905173 216645758 295796813 315837474 320406533 587581200 752141234 678712754 861201043 966149510 621595012 943712991 262515702 70048484 7673...
output:
0 865991452 631700724 190979249 400583525 172126966 793552793 503341034 803130294 8596920 179142401 176839944 552528706 157626285 317672757 183265987 493380846 63379432 188240507 944560633 607568693 552762996 575599493 693468972 804971832 67860545 841084350 811027293 995585882 507691985 47586486 144...
result:
ok 49998 numbers