#include <bits/stdc++.h>
using namespace std;
#define LL long long
inline int read() {
int x = 0, f = 1; char a = getchar();
for(; ! isdigit(a); a = getchar()) if(a == '-') f = -1;
for(; isdigit(a); a = getchar()) x = x * 10 + a - '0';
return x * f;
}
namespace Mathematicas {
const int P = 998244353;
inline int Mod(int x) { return x + ((x >> 31) & P); }
int power(int x, int k) {
int res = 1;
while(k) {
if(k & 1) res = (LL) res * x % P;
x = (LL) x * x % P; k >>= 1;
}
return res;
}
const int G = 3;
const int Gi = power(G, P - 2);
int lim, bit;
vector<int> rev;
void init(int n) {
lim = 1, bit = 0;
while(lim < n) lim <<= 1, bit ++;
rev.resize(lim);
for(int i = 0; i < lim; i ++)
rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
}
class Poly {
public :
vector<int> A;
int lenth;
Poly(int len) {
lenth = len; A.resize(lenth);
}
void resize(int len);
void clear();
void print();
int& operator [](int id) { return A[id]; }
} ;
void Poly :: resize(int len) {
while(A.size() < len) A.push_back(0);
while(A.size() > len) A.pop_back();
for(int i = lenth; i < len; i ++) A[i] = 0;
lenth = len;
}
void Poly :: clear() { A.clear(); A.resize(lenth); }
void Poly :: print() {
for(int i = 0; i < lenth; i ++) printf("%d ", A[i]);
putchar('\n');
}
Poly operator +(Poly x, Poly y) {
int len = max(x.lenth, y.lenth);
x.resize(len); y.resize(len);
for(int i = 0; i < len; i ++) x[i] = Mod(x[i] + y[i] - P);
return x;
}
Poly operator -(Poly x, Poly y) {
int len = max(x.lenth, y.lenth);
x.resize(len); y.resize(len);
for(int i = 0; i < len; i ++) x[i] = Mod(x[i] - y[i]);
return x;
}
void NTT(Poly &A, int type) {
A.resize(lim);
for(int i = 0; i < lim; i ++)
if(i < rev[i]) swap(A[i], A[rev[i]]);
for(int dep = 1; dep < lim; dep <<= 1) {
int Wn = power(type == 1 ? G : Gi, (P - 1) / (dep << 1));
for(int len = dep << 1, j = 0; j < lim; j += len) {
int w = 1;
for(int k = 0; k < dep; k ++, w = (LL) w * Wn % P) {
int x = A[j + k], y = (LL) A[j + k + dep] * w % P;
A[j + k] = Mod(x + y - P);
A[j + k + dep] = Mod(x - y);
}
}
}
if(type == -1) {
int inv = power(lim, P - 2);
for(int i = 0; i < lim; i ++) A[i] = (LL) A[i] * inv % P;
}
}
void DFT(Poly &A) { NTT(A, 1); }
void IDFT(Poly &A) { NTT(A, -1); }
Poly operator *(Poly A, Poly B) {
int len = A.lenth + B.lenth - 1;
init(len);
DFT(A); DFT(B);
for(int i = 0; i < lim; i ++) A[i] = (LL) A[i] * B[i] % P;
IDFT(A); A.resize(len);
return A;
}
}
using Mathematicas :: Poly;
int main() {
int n = read(), m = read();
Poly a(n + 1), b(m + 1);
for(int i = 0; i <= n; i ++) a[i] = read();
for(int i = 0; i <= m; i ++) b[i] = read();
a = a * b;
a.print();
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Subtask #1 Testcase #1 | 36.2 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #2 | 66.602 ms | 6 MB + 772 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #3 | 30.576 ms | 3 MB + 80 KB | Accepted | Score: 100 | 显示更多 |
| Subtask #1 Testcase #4 | 30.624 ms | 2 MB + 836 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #5 | 40.94 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #6 | 38.01 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #7 | 37.34 us | 36 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #8 | 61.549 ms | 6 MB + 740 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #9 | 61.483 ms | 6 MB + 228 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #10 | 56.325 ms | 5 MB + 440 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #11 | 66.93 ms | 6 MB + 852 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #12 | 67.638 ms | 5 MB + 732 KB | Accepted | Score: 0 | 显示更多 |
| Subtask #1 Testcase #13 | 35.09 us | 36 KB | Accepted | Score: 0 | 显示更多 |