提交记录 20541


用户 题目 状态 得分 用时 内存 语言 代码长度
konjaklaf 1002i. 【模板题】多项式乘法 Accepted 100 47.081 ms 13956 KB C++ 1.86 KB
提交时间 评测时间
2023-11-05 11:09:43 2023-11-05 11:09:50
#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef long double LD;
typedef long long LL;
typedef double db;
const int N = 500000;
const LL P = 998244353, G = 3, Gi = 332748118;
const LL inv2 = 499122177;
LL Pow(LL x, LL y) {
	LL res = 1;
	for (; y; y >>= 1, x = x * x % P)
		if (y & 1) res = res * x % P;
	return res;
}
int rev[N];
typedef vector<LL> poly;
inline LL ADD(LL x, LL y) { return (x += y) >= P ? x - P : x; }
inline LL DEL(LL x, LL y) { return (x -= y) < 0 ? x + P : x; }
void csz(poly &x, int n = 0) { x.resize(n), x.shrink_to_fit(); }
LL wn[N];
int pre(int len) {
	int i, j, tg, n = 1;
	while (n < len) n <<= 1;
	for (i = 1, wn[j = n >> 1] = 1; i < n; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? j : 0);
	for (i = j + 1, tg = Pow(Gi, (P - 1) / n); i < n; i++) wn[i] = wn[i - 1] * tg % P;
	for (i = j - 1; i > 0; i--) wn[i] = wn[i << 1];
	return n;
}
void ntt(poly &a, int n, int op = 0) {
	static LL f[N], *u, *v, *w, sv;
	int i, j, k; csz(a, n);
	for (i = 0; i < n; i++) f[i] = a[rev[i]];
	for (i = 1; i < n; i <<= 1)
		for (j = 0; j < n; j += i << 1)
			for (k = 0, w = wn + i, u = f + j, v = u + i; k < i; k++)
				sv = w[k] * v[k] % P, v[k] = DEL(u[k], sv), u[k] = ADD(u[k], sv);
	if (op) for (i = 0, sv = Pow(n, P - 2), reverse(f + 1, f + n); i < n; i++) f[i] = f[i] * sv % P;
	a.assign(f, f + n);
}
poly operator * (poly a, poly b) {
	const int n = a.size() + b.size() - 1, deg = pre(n);
	ntt(a, deg), ntt(b, deg);
	for (int i = 0; i < deg; i++) a[i] = a[i] * b[i] % P;
	return ntt(a, deg, 1), csz(a, n), a;
}
int n, m;
poly f, g;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	cin >> n >> m, ++n, ++m;
    csz(f, n), csz(g, m);
	for (int i = 0; i < n; i++) cin >> f[i];
    for (int i = 0; i < m; i++) cin >> g[i];
	f = f * g;
    for (int i = 0; i < n + m - 1; i++) cout << f[i] << ' ';
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #142.99 us72 KBAcceptedScore: 100

Subtask #1 Testcase #246.805 ms13 MB + 564 KBAcceptedScore: 0

Subtask #1 Testcase #320.559 ms7 MB + 392 KBAcceptedScore: 0

Subtask #1 Testcase #420.451 ms6 MB + 916 KBAcceptedScore: 0

Subtask #1 Testcase #545.01 us72 KBAcceptedScore: 0

Subtask #1 Testcase #643.72 us72 KBAcceptedScore: 0

Subtask #1 Testcase #743.81 us72 KBAcceptedScore: 0

Subtask #1 Testcase #842.38 ms12 MB + 780 KBAcceptedScore: 0

Subtask #1 Testcase #942.308 ms12 MB + 780 KBAcceptedScore: 0

Subtask #1 Testcase #1038.037 ms11 MB + 996 KBAcceptedScore: 0

Subtask #1 Testcase #1147.081 ms13 MB + 644 KBAcceptedScore: 0

Subtask #1 Testcase #1243.644 ms12 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #1342.53 us68 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-04 01:39:52 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用