提交记录 8027


用户 题目 状态 得分 用时 内存 语言 代码长度
changle_cyx 1002i. 【模板题】多项式乘法 Accepted 100 43.315 ms 4652 KB C++ 1.82 KB
提交时间 评测时间
2019-01-27 18:32:35 2020-08-01 01:11:46
#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)
{
	if (!x) return (void)(putchar('0')); 
	static char buf[15]; 
	static char *tail = buf; 
	for (; x; x /= 10) *++tail = x % 10 + '0'; 
	for (; tail != buf; --tail) putchar(*tail); 
}

const int MaxN = 1e6 + 5; 
const int mod = 998244353; 
//g = 3, mod = 119 * 2^23 + 1

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

inline int inc(int a, const int &b)
{
	a += b; return a >= mod ? a - mod : a; 
}

inline int dec(int a, const int &b)
{
	a -= b; return a < 0 ? a + mod : a; 
}

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, int n, const int &opt)
{
	for (int i = 0; i < n; ++i)
		if (i < rev[i]) std::swap(a[i], a[rev[i]]); 
	int g = opt == 1 ? 3 : 332748118; 
	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; 
				a[i + j] = inc(u, v), a[i + j + k] = dec(u, v); 
				x = 1LL * x * omega % mod; 
			}
		}
	}
}

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]); 
	
	L = 1; 
	while (n + m >= L) L <<= 1, ++K; 
	
	for (int i = 1; i <= L; ++i)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << K - 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); 
	
	int inv = qpow(L, mod - 2); 
	for (int i = 0; i <= n + m; ++i)
		putint(1LL * a[i] * inv % mod), putchar(' '); 
	
	return 0; 
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #134.85 us48 KBAcceptedScore: 0

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

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

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

Subtask #1 Testcase #538.72 us48 KBAcceptedScore: 0

Subtask #1 Testcase #635.87 us48 KBAcceptedScore: 0

Subtask #1 Testcase #735.13 us48 KBAcceptedScore: 0

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

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

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

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

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

Subtask #1 Testcase #1333.46 us48 KBAcceptedScore: 0


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