結果

問題 No.931 Multiplicative Convolution
ユーザー noshi91
提出日時 2019-11-22 22:12:53
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 4,727 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 75,208 KB
実行使用メモリ 13,188 KB
最終ジャッジ日時 2024-10-11 03:52:41
合計ジャッジ時間 2,641 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>
namespace n91 {
using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;
struct rep {
struct itr {
usize i;
constexpr itr(const usize i) noexcept : i(i) {}
void operator++() noexcept { ++i; }
constexpr usize operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
const itr f, l;
constexpr rep(const usize f, const usize l) noexcept
: f(std::min(f, l)), l(l) {}
constexpr auto begin() const noexcept { return f; }
constexpr auto end() const noexcept { return l; }
};
struct revrep {
struct itr {
usize i;
constexpr itr(const usize i) noexcept : i(i) {}
void operator++() noexcept { --i; }
constexpr usize operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
const itr f, l;
constexpr revrep(const usize f, const usize l) noexcept
: f(l - 1), l(std::min(f, l) - 1) {}
constexpr auto begin() const noexcept { return f; }
constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
if (b < a)
a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
if (a < b)
a = b;
}
template <class T> T scan() {
T ret;
std::cin >> ret;
return ret;
}
} // namespace n91
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <vector>
namespace n91 {
using usize = std::size_t;
using u64 = std::uint_fast64_t;
static constexpr u64 Modulus = 998244353;
static constexpr u64 PrimitiveRoot = 3;
void ntt(std::vector<u64> &a) {
const usize size = a.size();
const usize m = size - 1;
std::vector<u64> b(size);
u64 root = 1;
{
u64 base = PrimitiveRoot;
u64 exp = (Modulus - 1) / size;
while (exp != 0) {
if (exp % 2 != 0) {
root = root * base % Modulus;
}
exp /= 2;
base = base * base % Modulus;
}
}
for (usize i = size; (i /= 2) != 0;) {
std::swap(a, b);
u64 c = 1;
u64 d = root;
for (usize j = 1; j != i; j *= 2) {
d = d * d % Modulus;
}
for (usize j = 0; j != size; j += i) {
const usize l = j * 2 & m, r = l + i;
for (usize k = 0; k != i; ++k) {
a[j + k] = (b[l + k] + b[r + k] * c) % Modulus;
}
c = c * d % Modulus;
}
}
}
void inv_ntt(std::vector<u64> &a) {
ntt(a);
std::reverse(a.begin() + 1, a.end());
const u64 inv = Modulus - (Modulus - 1) / a.size();
for (auto &e : a) {
e = e * inv % Modulus;
}
}
} // namespace n91
#include <algorithm>
#include <iostream>
#include <utility>
namespace n91 {
void main_() {
//*
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
//*/
const u64 p = scan<u64>();
const auto is_pr = [&](const u64 a) {
u64 t = 1;
for (const usize i : rep(0, p - 2)) {
t = t * a % p;
if (t == 1) {
return false;
}
}
return true;
};
const u64 proot = [&]() {
for (u64 i = 1; i < p; i += 1) {
if (is_pr(i)) {
return i;
}
}
assert(false);
}();
std::vector<u64> A(p), B(p);
for (const usize i : rep(1, p)) {
std::cin >> A[i];
}
for (const usize i : rep(1, p)) {
std::cin >> B[i];
}
const usize s = [&]() {
usize s = 1;
while (s < p - 1) {
s *= 2;
}
return s * 2;
}();
std::vector<u64> a(s), b(s);
{
u64 t = 1;
for (const usize i : rep(0, p - 1)) {
a[i] = A[t];
b[i] = B[t];
t = t * proot % p;
}
}
ntt(a);
ntt(b);
std::vector<u64> c(s);
for (const usize i : rep(0, s)) {
c[i] = a[i] * b[i] % Modulus;
}
inv_ntt(c);
for (const usize i : rep(p - 1, s)) {
c[i % (p - 1)] = (c[i % (p - 1)] + c[i]) % Modulus;
}
std::vector<u64> C(p);
{
u64 t = 1;
for (const usize i : rep(0, p - 1)) {
C[t] = c[i];
t = t * proot % p;
}
}
for (const usize i : rep(1, p)) {
std::cout << C[i] << (i != p - 1 ? ' ' : '\n');
}
}
} // namespace n91
int main() {
n91::main_();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0