提交记录 15023


用户 题目 状态 得分 用时 内存 语言 代码长度
CzxingcHen 1002i. 【模板题】多项式乘法 Accepted 100 80.602 ms 6676 KB C++ 1.60 KB
提交时间 评测时间
2020-11-15 07:44:52 2020-11-15 07:44:55
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

const int N = 3e5 + 5;
const ll P = 998244353;

int n, m, lim = 1, pos[N];
ll a[N], b[N];

template <typename T>
inline void read(T &X) {
	X = 0; char ch = 0; T op = 1;
	for (; ch > '9' || ch < '0'; ch = getchar())
		if(ch == '-') op = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar())
		X = (X << 3) + (X << 1) + ch - 48;
	X *= op;
}

template <typename T>
inline void swap(T &x, T &y) {
	T t = x; x = y; y = t;
}

inline ll fpow(ll x, ll y) {
	ll res = 1LL;
	for (; y > 0; y >>= 1) {
		if (y & 1) res = res * x % P;
		x = x * x % P;
	}
	return res;
}

inline void prework() {
	int l = 0;
	for (; lim <= n + m + 1; ++l, lim <<= 1);
	for (int i = 0; i <= lim; i++)
		pos[i] = (pos[i >> 1] >> 1) | ((i & 1) << (l - 1));
}

inline void NTT(ll *c, int opt) {
	for (int i = 0; i < lim; i++)
		if(i < pos[i]) swap(c[i], c[pos[i]]);
	for (int i = 1; i < lim; i <<= 1) {
		ll wn = fpow(3, (P - 1) / (i << 1));
		if(opt == -1) wn = fpow(wn, P - 2);
		for (int len = i << 1, j = 0; j < lim; j += len) {
			ll w = 1;
			for(int k = 0; k < i; k++, w = w * wn % P) {
				ll x = c[j + k], y = w * c[j + k + i] % P;
				c[j + k] = (x + y) % P, c[j + k + i] = (x - y + P) % P;
			}
		}
	}
}

int main() {
	read(n), read(m);
	for (int i = 0; i <= n; i++) read(a[i]);
	for (int i = 0; i <= m; i++) read(b[i]);
	
	prework();
	NTT(a, 1), NTT(b, 1);
	for (int i = 0; i < lim; i++) a[i] = a[i] * b[i] % P;
	NTT(a, -1);
	
	ll inv = fpow(lim, P - 2);
	for (int i = 0; i <= n + m; i++) {
		a[i] = a[i] * inv % P;
		printf("%lld%c", a[i], i == n + m ? '\n' : ' ');
	}
	
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #19.9 us24 KBAcceptedScore: 0

Subtask #1 Testcase #279.879 ms6 MB + 452 KBAcceptedScore: 0

Subtask #1 Testcase #337.64 ms2 MB + 816 KBAcceptedScore: 100

Subtask #1 Testcase #437.706 ms2 MB + 804 KBAcceptedScore: 0

Subtask #1 Testcase #510.75 us24 KBAcceptedScore: 0

Subtask #1 Testcase #610.27 us24 KBAcceptedScore: 0

Subtask #1 Testcase #710.39 us24 KBAcceptedScore: 0

Subtask #1 Testcase #872.809 ms6 MB + 184 KBAcceptedScore: 0

Subtask #1 Testcase #972.909 ms6 MB + 184 KBAcceptedScore: 0

Subtask #1 Testcase #1065.699 ms5 MB + 940 KBAcceptedScore: 0

Subtask #1 Testcase #1180.347 ms6 MB + 532 KBAcceptedScore: 0

Subtask #1 Testcase #1280.602 ms5 MB + 412 KBAcceptedScore: 0

Subtask #1 Testcase #138.18 us24 KBAcceptedScore: 0


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