提交记录 8039


用户 题目 状态 得分 用时 内存 语言 代码长度
changle_cyx 1002i. 【模板题】多项式乘法 Accepted 100 72.787 ms 4652 KB C++ 1.95 KB
提交时间 评测时间
2019-01-27 20:21:21 2020-08-01 01:11:53
#include <bits/stdc++.h>

template <class T>
inline void read(T &x)
{
	static char ch; 
	while (!isdigit(ch = getchar())); 
	x = ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
}

template <class T>
inline void putint(T x)
{
	static char buf[15], *tail = buf; 
	if (!x) return (void)(putchar('0')); 
	for (; x; x /= 10) *++tail = x % 10 + '0'; 
	for (; tail != buf; --tail) putchar(*tail); 
}	

const int MaxN = 1e6 + 5; 
const int mod = 998244353; 

int n, m, rev[MaxN], a[MaxN], b[MaxN]; 
int P, L; 

inline void add(int &x, const int &y)
{
	x += y; 
	if (x >= mod) x -= mod; 
	if (x < 0) x += mod; 
}

inline void poly_init(int n)
{
	P = 0, L = 1; 
	while (L < n) L <<= 1, ++P; 
	for (int i = 1; i < L; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << P - 1); 
}

inline int qpow(int a, int b)
{
	int res = 1; 
	for (; b; b >>= 1, a = 1LL * a * a % mod)
		if (b & 1) res = 1LL * res * a % mod;
	return res;  
}

inline void DFT(int *a, const int &n, const int &opt)
{
	for (int i = 1; i < n; ++i)
		if (i < rev[i]) std::swap(a[i], a[rev[i]]); 
	
	int g = opt == 1 ? 3 : (mod + 1) / 3; 
	for (int k = 1; k < n; k <<= 1)
	{
		int omega = qpow(g, (mod - 1) / (k << 1)); 
		for (int i = 0; i < n; i += k << 1)
		{
			int x = 1; 
			for (int j = 0; j < k; ++j)
			{
				int u = a[i + j], v = 1LL * a[i + j + k] * x % mod; 
				add(a[i + j] = u, v); 
				add(a[i + j + k] = u, -v); 
				x = 1LL * x * omega % mod; 
			}
		}
	}
	
	if (opt == -1)
	{
		int inv = qpow(n, mod - 2); 
		for (int i = 0; i < n; ++i)
			a[i] = 1LL * a[i] * inv % mod; 
	}
}

int main()
{
#ifdef orzczk
	freopen("weak.in", "r", stdin); 
#endif

	read(n), read(m); ++n, ++m; 
	for (int i = 0; i < n; ++i) read(a[i]); 
	for (int i = 0; i < m; ++i) read(b[i]); 
	
	poly_init(n + m - 1); 
	DFT(a, L, 1), DFT(b, L, 1); 
	
	for (int i = 0; i < L; ++i) a[i] = 1LL * a[i] * b[i] % mod; 
	
	DFT(a, L, -1); 
	
	for (int i = 0; i < n + m - 1; ++i)
		putint(a[i]), putchar(" \n"[i == n + m - 2]); 
	
	return 0; 
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #134.4 us48 KBAcceptedScore: 0

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

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

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

Subtask #1 Testcase #536.12 us48 KBAcceptedScore: 0

Subtask #1 Testcase #633.31 us48 KBAcceptedScore: 0

Subtask #1 Testcase #734.46 us48 KBAcceptedScore: 0

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

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

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

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

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

Subtask #1 Testcase #1333.25 us44 KBAcceptedScore: 0


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