提交记录 16777


用户 题目 状态 得分 用时 内存 语言 代码长度
Saisyc 1002i. 【模板题】多项式乘法 Accepted 100 75.289 ms 5680 KB C++ 1.91 KB
提交时间 评测时间
2021-10-18 02:02:53 2021-10-18 02:02:57
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int N = 1 << 21, P = 998244353;

inline int qpow(int x, int y) {
  int res(1);
  while (y) {
    if (y & 1) res = 1ll * res * x % P;
    x = 1ll * x * x % P;
    y >>= 1;
  }
  return res;
}

int r[N];

void ntt(int *x, int lim, int opt) {
  register int i, j, k, m, gn, g, tmp;
  for (i = 0; i < lim; ++i)
    if (r[i] < i) swap(x[i], x[r[i]]);
  for (m = 2; m <= lim; m <<= 1) {
    k = m >> 1;
    gn = qpow(3, (P - 1) / m);
    for (i = 0; i < lim; i += m) {
      g = 1;
      for (j = 0; j < k; ++j, g = 1ll * g * gn % P) {
        tmp = 1ll * x[i + j + k] * g % P;
        x[i + j + k] = (x[i + j] - tmp + P) % P;
        x[i + j] = (x[i + j] + tmp) % P;
      }
    }
  }
  if (opt == -1) {
    reverse(x + 1, x + lim);
    register int inv = qpow(lim, P - 2);
    for (i = 0; i < lim; ++i) x[i] = 1ll * x[i] * inv % P;
  }
}

int A[N], B[N], C[N];

int n, n_a, n_b;

int main(void) {
	scanf("%d%d", &n_a, &n_b); for(n = 1; n <= n_a + n_b; n <<= 1);
	for(int i = 0; i <= n_a; ++i) scanf("%d", A + i); 
	for(int i = 0; i <= n_b; ++i) scanf("%d", B + i);
	
	for(int i = 0; i < n; ++i) r[i] = (i & 1) * (n >> 1) + (r[i >> 1] >> 1);
	ntt(A, n, 1); ntt(B, n, 1);
	for(int i = 0; i < n; ++i) C[i] = 1ll * A[i] * B[i] % P;
	ntt(C, n, -1);
	for(int i = 0; i <= n_a + n_b; ++i) printf("%d ", C[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.72 us52 KBAcceptedScore: 0

Subtask #1 Testcase #275.15 ms5 MB + 480 KBAcceptedScore: 100

Subtask #1 Testcase #334.755 ms2 MB + 332 KBAcceptedScore: 0

Subtask #1 Testcase #434.805 ms2 MB + 320 KBAcceptedScore: 0

Subtask #1 Testcase #539.1 us52 KBAcceptedScore: 0

Subtask #1 Testcase #637.48 us52 KBAcceptedScore: 0

Subtask #1 Testcase #737.33 us52 KBAcceptedScore: 0

Subtask #1 Testcase #869.341 ms5 MB + 212 KBAcceptedScore: 0

Subtask #1 Testcase #969.233 ms5 MB + 212 KBAcceptedScore: 0

Subtask #1 Testcase #1063.564 ms4 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #1175.125 ms5 MB + 560 KBAcceptedScore: 0

Subtask #1 Testcase #1275.289 ms4 MB + 440 KBAcceptedScore: 0

Subtask #1 Testcase #1335.44 us52 KBAcceptedScore: 0


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