提交记录 13364


用户 题目 状态 得分 用时 内存 语言 代码长度
jzp 1002i. 【模板题】多项式乘法 Accepted 100 71.87 ms 6700 KB C++ 1.86 KB
提交时间 评测时间
2020-08-01 11:42:34 2020-08-01 11:42:37
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
#define N 4001000
typedef long long ll;
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
const int P = 998244353;
const int G = 3;
const int Gi = (P + 1) / G;
int n, m;
ll A[N], B[N];
int limi = 1, r[N], L;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
inline void ntt(ll *a, int type) {
	for (register int i = 1; i < limi; ++i)
		if (i < r[i])	swap(a[i], a[r[i]]);
	for (register int i = 1; i < limi; i <<= 1) {//?
		ll T = quickpow(type == 1 ? G : Gi, (P - 1) / (i << 1));//Attention!!
		for (register int j = 0; j < limi; j += (i << 1)) {
			ll t = 1;
			for (register int k = 0; k < i; ++k, t = t * T % P) {//Attention!! : % P
				ll nx = a[j + k], ny = a[j + k + i] * t % P;
				a[j + k] = (nx + ny) % P;
				a[j + k + i] = (nx - ny + P) % P;
			}
		}
	}
	if (type == -1) {
		ll inv = quickpow(limi, P - 2);
		for (register int i = 0; i < limi; ++i)
			a[i] = a[i] * inv % P;
	}
}
inline void mul(ll *a, ll *b, int n, int m) {
	while (limi <= (n + m))	limi <<= 1, ++L;
	for (register int i = 1; i < limi; ++i)
		r[i] = (r[i >> 1] >> 1) | ((i & 1) << (L - 1));
	ntt(a, 1), ntt(b, 1);
	for (register int i = 0; i < limi; ++i)	a[i] = a[i] * b[i] % P;
	ntt(a, -1);
}
int main() {
	read(n), read(m);
	for (register int i = 0; i <= n; ++i)	read(A[i]);
	for (register int j = 0; j <= m; ++j)	read(B[j]);
	mul(A, B, n, m);
	for (register int i = 0; i <= n + m; ++i) {
		printf("%lld ", A[i]);
	}
	return 0;
}

/*
1 2
1 2
1 2 1
//1 4 5 2
*/

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #137.07 us48 KBAcceptedScore: 0

Subtask #1 Testcase #271.012 ms6 MB + 476 KBAcceptedScore: 100

Subtask #1 Testcase #333.1 ms2 MB + 840 KBAcceptedScore: 0

Subtask #1 Testcase #433.111 ms2 MB + 828 KBAcceptedScore: 0

Subtask #1 Testcase #539 us48 KBAcceptedScore: 0

Subtask #1 Testcase #637 us48 KBAcceptedScore: 0

Subtask #1 Testcase #736.7 us48 KBAcceptedScore: 0

Subtask #1 Testcase #865.843 ms6 MB + 208 KBAcceptedScore: 0

Subtask #1 Testcase #965.722 ms6 MB + 208 KBAcceptedScore: 0

Subtask #1 Testcase #1060.507 ms5 MB + 964 KBAcceptedScore: 0

Subtask #1 Testcase #1171.31 ms6 MB + 556 KBAcceptedScore: 0

Subtask #1 Testcase #1271.87 ms5 MB + 436 KBAcceptedScore: 0

Subtask #1 Testcase #1334.87 us48 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-24 12:15:21 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠