#include <cstdio>
#include <cctype>
#include <algorithm>
typedef unsigned int uint;
typedef long long unsigned int uint64;
struct IO_Tp
{
const static int _I_Buffer_Size = 2 << 20;
char _I_Buffer[_I_Buffer_Size], *_I_pos = _I_Buffer;
const static int _O_Buffer_Size = 2 << 20;
char _O_Buffer[_O_Buffer_Size], *_O_pos = _O_Buffer;
IO_Tp() { fread(_I_Buffer, 1, _I_Buffer_Size, stdin); }
~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }
IO_Tp &operator>>(int &res)
{
while (!isdigit(*_I_pos))
++_I_pos;
res = *_I_pos++ & 15;
while (isdigit(*_I_pos))
res = res * 10 + (*_I_pos++ & 15);
return *this;
}
IO_Tp &operator>>(uint &res)
{
while (!isdigit(*_I_pos))
++_I_pos;
res = *_I_pos++ & 15;
while (isdigit(*_I_pos))
res = res * 10 + (*_I_pos++ & 15);
return *this;
}
IO_Tp &operator<<(uint n)
{
static char _buf[10];
char* _pos = _buf;
do
*_pos++ = '0' + n % 10;
while (n /= 10);
while (_pos != _buf)
*_O_pos++ = *--_pos;
return *this;
}
IO_Tp &operator<<(char ch)
{
*_O_pos++ = ch;
return *this;
}
} IO;
constexpr uint Max_size = 1 << 18 | 5;
constexpr uint g = 3, Mod = 998244353;
struct Z
{
uint v;
Z(const uint _v = 0) : v(_v) { }
};
inline Z operator+(const Z &x1, const Z &x2) { return x1.v + x2.v < Mod ? x1.v + x2.v : x1.v + x2.v - Mod; }
inline Z operator-(const Z &x1, const Z &x2) { return x1.v >= x2.v ? x1.v - x2.v : x1.v + Mod - x2.v; }
inline Z operator*(const Z &x1, const Z &x2) { return static_cast<uint64>(x1.v) * x2.v % Mod; }
inline Z &operator*=(Z &x1, const Z &x2) { x1.v = static_cast<uint64>(x1.v) * x2.v % Mod; return x1; }
Z Power(Z Base, int Exp)
{
Z res = 1;
for (; Exp; Base *= Base, Exp >>= 1)
if (Exp & 1)
res *= Base;
return res;
}
inline uint mf(uint x)
{
return (static_cast<uint64>(x) << 32) / Mod;
}
int size;
uint w[Max_size], w_mf[Max_size];
inline void init(int n)
{
for (size = 2; size < n; size <<= 1)
;
Z pr = Power(g, (Mod - 1) / size);
w[size / 2] = 1, w_mf[size / 2] = mf(w[size / 2]);
for (int i = 1; i < size / 2; ++i)
w[size / 2 + i] = (w[size / 2 + i - 1] * pr).v, w_mf[size / 2 + i] = mf(w[size / 2 + i]);
for (int i = size / 2 - 1; i; --i)
w[i] = w[i << 1], w_mf[i] = w_mf[i << 1];
}
inline void DIF_NTT_core_2(Z _A[], const int L)
{
uint *A = reinterpret_cast<uint *>(_A);
for (int d = L >> 1; d; d >>= 1)
for (int i = 0; i != L; i += d << 1)
for (int j = 0; j != d; ++j)
{
uint x = A[i + j] + A[i + d + j];
if (x >= Mod * 2)
x -= Mod * 2;
uint64 t = A[i + j] + Mod * 2 - A[i + d + j];
uint64 q = t * w_mf[d + j] >> 32;
uint y = t * w[d + j] - q * Mod;
A[i + j] = x, A[i + d + j] = y;
}
}
inline void DIT_INTT_core_2(Z _A[], const int L)
{
uint *A = reinterpret_cast<uint *>(_A);
for (int d = 1; d != L; d <<= 1)
for (int i = 0; i != L; i += d << 1)
for (int j = 0; j != d; ++j)
{
uint x = A[i + j];
if (x >= Mod * 2)
x -= Mod * 2;
uint64 y = A[i + d + j];
uint64 q = y * w_mf[d + j] >> 32;
uint64 t = y * w[d + j] - q * Mod;
A[i + j] = x + t, A[i + d + j] = x + Mod * 2 - t;
}
std::reverse(A + 1, A + L);
if (L == 2)
{
if (A[0] >= Mod * 2)
A[0] -= Mod * 2;
if (A[1] >= Mod * 2)
A[1] -= Mod * 2;
}
int k = __builtin_ctz(L);
for (int i = 0; i != L; ++i)
{
uint64 m = -A[i] & (L - 1);
A[i] = (A[i] + m * Mod) >> k;
}
}
inline void normalize_2(Z _A[], const int L)
{
uint *A = reinterpret_cast<uint *>(_A);
for (int i = 0; i != L; ++i)
if (A[i] >= Mod)
A[i] -= Mod;
}
int N, M, L;
Z A[Max_size], B[Max_size];
int main(int argc, char **argv)
{
IO >> N >> M;
for (int i = 0; i <= N; ++i)
IO >> A[i].v;
for (int i = 0; i <= M; ++i)
IO >> B[i].v;
for (L = 2; L <= N + M; L <<= 1)
;
init(L);
DIF_NTT_core_2(A, L), DIF_NTT_core_2(B, L);
for (int i = 0; i != L; ++i)
A[i] *= B[i];
DIT_INTT_core_2(A, L), normalize_2(A, L);
for (int i = 0; i <= N + M; ++i)
IO << A[i].v << ' ';
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Subtask #1 Testcase #1 | 295.5 us | 2 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #2 | 17.952 ms | 7 MB + 256 KB | Accepted | Score: 100 | 显示更多 |
Subtask #1 Testcase #3 | 7.635 ms | 3 MB + 796 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #4 | 7.651 ms | 3 MB + 776 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #5 | 295.31 us | 2 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #6 | 296.74 us | 2 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #7 | 296.38 us | 2 MB + 40 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #8 | 17.26 ms | 6 MB + 676 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #9 | 17.227 ms | 6 MB + 676 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #10 | 16.474 ms | 6 MB + 72 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #11 | 18.138 ms | 7 MB + 416 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #12 | 15.199 ms | 5 MB + 172 KB | Accepted | Score: 0 | 显示更多 |
Subtask #1 Testcase #13 | 296.4 us | 2 MB + 40 KB | Accepted | Score: 0 | 显示更多 |