提交记录 11877


用户 题目 状态 得分 用时 内存 语言 代码长度
denverjin 1002i. 【模板题】多项式乘法 Accepted 100 53.852 ms 6688 KB C++ 2.22 KB
提交时间 评测时间
2020-02-18 20:43:03 2020-08-01 02:48:50
#include <bits/stdc++.h>
using namespace std;

const int mod = 998244353, g = 3;
const int N = 1 << 18;

int qp(int x, int n) {
	int ans = 1;
	for (; n; n >>= 1, x = 1LL * x * x % mod)
		n & 1 && (ans = 1LL * ans * x % mod);
	return ans;
}
int inv(int x) {return qp(x, mod - 2);}

int add(int x, int y) {return x + y < mod ? x + y : x + y - mod;}
int sub(int x, int y) {return x - y >= 0 ? x - y : x - y + mod;}

int W[N], r[N];

void ntt(int *a, int n, int f) {
	int k = __builtin_ctz(n);
	for (int i = 1; i < n - 1; ++ i) {
		r[i] = r[i >> 1] >> 1 | (i & 1) << k - 1;
		if (i < r[i]) swap(a[i], a[r[i]]);
	}
	if (n >= 2) {
		for (int i = 0, v; i < n; i += 2) {
			v = a[i + 1];
			a[i + 1] = sub(a[i], v), a[i] = add(a[i], v);
		}
	}
	if (n >= 4) {
		for (int i = 0, v; i < n; i += 4) {
			v = 1LL * a[i + 2] * W[2] % mod;
			a[i + 2] = sub(a[i], v); a[i] = add(a[i], v);
			v = 1LL * a[i + 3] * W[3] % mod;
			a[i + 3] = sub(a[i + 1], v), a[i + 1] = add(a[i + 1], v);
		}
	}
	for (int h = 4; h < n; h <<= 1) {
		for (int i = 0; i < n; i += h << 1) {
			int *w = W + h, *ed = W + (h << 1), *u = a + i, *v = a + i + h, x;
			#define S(u, v, w)               \
				x = 1LL * *(v) * *(w) % mod; \
				*(v) = sub(*(u), x);         \
				*(u) = add(*(u), x);
			while (w < ed) {
				S(u + 0, v + 0, w + 0)
				S(u + 1, v + 1, w + 1)
				S(u + 2, v + 2, w + 2)
				S(u + 3, v + 3, w + 3)
				u += 4, v += 4, w += 4;
			}
		}
	}
	if (!~f) {
		reverse(a + 1, a + n); int Inv = inv(n);
		for (int i = 0; i < n; ++ i) a[i] = 1LL * a[i] * Inv % mod;
	}
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	int siz = 1; while (siz < n + m + 1) siz <<= 1;
	for (int i = 1; i < siz; i <<= 1) {
		W[i] = 1; int wn = qp(g, (mod - 1) / (i << 1));
		for (int j = 1; j < i; ++ j)
			W[i + j] = 1LL * W[i + j - 1] * wn % mod;
	}
	int *a = new int[siz];
	for (int i = 0; i <= n; ++ i) scanf("%d", &a[i]);
	for (int i = n + 1; i < siz; ++ i) a[i] = 0;
	int *b = new int[siz];
	for (int i = 0; i <= m; ++ i) scanf("%d", &b[i]);
	for (int i = m + 1; i < siz; ++ i) b[i] = 0;
	ntt(a, siz, 1); ntt(b, siz, 1);
	int *c = new int[siz];
	for (int i = 0; i < siz; ++ i) c[i] = 1LL * a[i] * b[i] % mod;
	ntt(c, siz, -1);
	for (int i = 0; i <= n + m; ++ i) printf("%d ", c[i]); puts("");
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.7 us44 KBAcceptedScore: 0

Subtask #1 Testcase #253.481 ms6 MB + 464 KBAcceptedScore: 100

Subtask #1 Testcase #324.542 ms2 MB + 836 KBAcceptedScore: 0

Subtask #1 Testcase #424.564 ms2 MB + 824 KBAcceptedScore: 0

Subtask #1 Testcase #540.23 us44 KBAcceptedScore: 0

Subtask #1 Testcase #637.72 us44 KBAcceptedScore: 0

Subtask #1 Testcase #737.18 us44 KBAcceptedScore: 0

Subtask #1 Testcase #847.741 ms6 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #947.814 ms6 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #1042.002 ms5 MB + 952 KBAcceptedScore: 0

Subtask #1 Testcase #1153.679 ms6 MB + 544 KBAcceptedScore: 0

Subtask #1 Testcase #1253.852 ms5 MB + 424 KBAcceptedScore: 0

Subtask #1 Testcase #1335.59 us40 KBAcceptedScore: 0


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