提交记录 13982


用户 题目 状态 得分 用时 内存 语言 代码长度
Kewth 1002i. 【模板题】多项式乘法 Accepted 100 47.084 ms 8720 KB C++11 2.46 KB
提交时间 评测时间
2020-08-14 21:03:41 2020-08-14 21:03:44
/*
 * Author: Kewth

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Type "!!sh" in Vim.

 * Solution:
  To be updated after "Accept".

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆■▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef unsigned long long ull;

static struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
} read;

const int maxl = 1 << 18, mod = 998244353;
int R[maxl << 1], G[maxl];

inline ll power (ll x, int k) {
	if (k < 0) k += mod - 1;
	ll res = 1;
	while (k) {
		if (k & 1) (res *= x) %= mod;
		(x *= x) %= mod;
		k >>= 1;
	}
	return res;
}

void init () {
	for (int n = 1; n <= maxl; n <<= 1) {
		int *r = R + n;
		for (int i = 1; i < n; i ++)
			r[i] = r[i >> 1] >> 1 | (i & 1) * (n >> 1);
	}
	ll g = power(3, (mod - 1) / maxl);
	G[maxl / 2] = 1;
	for (int i = maxl / 2 + 1; i < maxl; i ++) G[i] = G[i - 1] * g % mod;
	for (int i = maxl / 2 - 1; i; i --) G[i] = G[i << 1];
}

void dft (int *b, int n) {
	static ull a[maxl];
	for (int i = 0; i < n; i ++) a[i] = ull(b[R[n + i]]);
	for (int m = 1; m < n; m <<= 1)
		for (int i = 0; i < n; i += m << 1)
			for (int k = i; k < i + m; k ++) {
				ull x = a[k], y = a[k + m] * ull(G[m + k - i]) % mod;
				a[k] = x + y;
				a[k + m] = x + mod - y;
			}
	for (int i = 0; i < n; i ++) b[i] = a[i] % mod;
}

void idft (int *a, int n) {
	std::reverse(a + 1, a + n), dft(a, n);
	ll inv = mod - (mod - 1) / n;
	for (int i = 0; i < n; i ++) a[i] = inv * a[i] % mod;
}

void polyinv (int *a, int n) {
	static int t[maxl], b[maxl];
	b[0] = int(power(a[0], -1));
	for (int m = 2; m <= n; m <<= 1) {
		std::copy(a, a + m, t);
		std::fill(t + m, t + (m << 1), 0);
		dft(t, m << 1), dft(b, m << 1);
		for (int i = 0; i < (m << 1); i ++)
			b[i] = ll(2 + ll(mod - t[i]) * b[i]) % mod * b[i] % mod;
		idft(b, m << 1);
		std::fill(b + m, b + (m << 1), 0);
	}
	std::copy(b, b + n, a);
}

int a[maxl], b[maxl];
int main () {
	init();
	int n = read, m = read, l = 1;
	while (l < n + m + 1) l <<= 1;
	for (int i = 0; i <= n; i ++) read(a[i]);
	for (int i = 0; i <= m; i ++) read(b[i]);
	dft(a, l), dft(b, l);
	for (int i = 0; i < l; i ++) a[i] = 1ll * a[i] * b[i] % mod;
	idft(a, l);
	for (int i = 0; i <= n + m; i ++) printf("%d ", a[i]); puts("");
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.154 ms3 MB + 32 KBAcceptedScore: 0

Subtask #1 Testcase #246.608 ms8 MB + 448 KBAcceptedScore: 0

Subtask #1 Testcase #321.897 ms5 MB + 312 KBAcceptedScore: 100

Subtask #1 Testcase #422.194 ms5 MB + 300 KBAcceptedScore: 0

Subtask #1 Testcase #51.156 ms3 MB + 32 KBAcceptedScore: 0

Subtask #1 Testcase #61.155 ms3 MB + 32 KBAcceptedScore: 0

Subtask #1 Testcase #71.161 ms3 MB + 32 KBAcceptedScore: 0

Subtask #1 Testcase #841.002 ms8 MB + 180 KBAcceptedScore: 0

Subtask #1 Testcase #940.998 ms8 MB + 180 KBAcceptedScore: 0

Subtask #1 Testcase #1035.356 ms7 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #1147.006 ms8 MB + 528 KBAcceptedScore: 0

Subtask #1 Testcase #1247.084 ms7 MB + 408 KBAcceptedScore: 0

Subtask #1 Testcase #131.161 ms3 MB + 32 KBAcceptedScore: 0


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