提交记录 8955


用户 题目 状态 得分 用时 内存 语言 代码长度
YeahPotato 1002i. 【模板题】多项式乘法 Accepted 100 75.498 ms 4652 KB C++ 1.33 KB
提交时间 评测时间
2019-03-26 17:52:00 2020-08-01 01:27:39
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define MOD 998244353
typedef long long ll;
const int N = 3e5+5;
int n, m, f[N], len = 1, lim;
int a[N], b[N], Ilen;
inline int qpow(int x, int y) {
	int t = 1;
	while (y) {
		if (y & 1) t = 1ll * t * x % MOD;
		x = 1ll * x * x % MOD, y >>= 1;
	} return t;
}
inline int PLUS(int x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
	if (x < 0) x += MOD;
	return x;
}
void NTT(int *a, int n, bool op) {
	for (int i=0; i<n; i++)
		if (i < f[i]) swap(a[i], a[f[i]]);
	for (int m=1; m<n; m<<=1) {
		int omega = qpow(3, (MOD - 1) / (m << 1));
		for (int i=0; i<n; i+=m<<1) {
			int x = 1;
			for (int j=0; j<m; j++, x=1ll*x*omega%MOD) {
				int tmp = 1ll * x * a[i + j + m] % MOD;
				a[i + j + m] = (a[i + j] - tmp + MOD) % MOD;
				a[i + j] = (a[i + j] + tmp) % MOD;
			}
		}
	}
	if (op) reverse (a+1, a+n);
}
int main() {
	cin >> n >> m;
	for (int i=0; i<=n; i++)
		scanf ("%d", &a[i]);
	for (int i=0; i<=m; i++)
		scanf ("%d", &b[i]);
	n += m;
	while (len <= n) ++lim, len <<= 1;
	Ilen = qpow(len, MOD - 2);
	for (int i=0; i<len; i++)
		f[i] = f[i >> 1] >> 1 | (i & 1) << lim - 1;
	NTT(a, len, 0), NTT(b, len, 0);
	for (int i=0; i<len; i++)
		a[i] = 1ll * a[i] * b[i] % MOD;
	NTT(a, len, 1);
	for (int i=0; i<=n; i++)
		printf ("%d ", 1ll * a[i] * Ilen % MOD);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #138.83 us48 KBAcceptedScore: 0

Subtask #1 Testcase #275.231 ms4 MB + 476 KBAcceptedScore: 100

Subtask #1 Testcase #334.824 ms1 MB + 840 KBAcceptedScore: 0

Subtask #1 Testcase #434.849 ms1 MB + 828 KBAcceptedScore: 0

Subtask #1 Testcase #541.49 us48 KBAcceptedScore: 0

Subtask #1 Testcase #639.11 us48 KBAcceptedScore: 0

Subtask #1 Testcase #738.79 us48 KBAcceptedScore: 0

Subtask #1 Testcase #869.488 ms4 MB + 208 KBAcceptedScore: 0

Subtask #1 Testcase #969.494 ms4 MB + 208 KBAcceptedScore: 0

Subtask #1 Testcase #1063.761 ms3 MB + 964 KBAcceptedScore: 0

Subtask #1 Testcase #1175.348 ms4 MB + 556 KBAcceptedScore: 0

Subtask #1 Testcase #1275.498 ms3 MB + 436 KBAcceptedScore: 0

Subtask #1 Testcase #1337.72 us48 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-05 08:19:45 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠