提交记录 18030


用户 题目 状态 得分 用时 内存 语言 代码长度
fragment 1002. 测测你的多项式乘法 Accepted 100 206.065 ms 57000 KB C++11 1.65 KB
提交时间 评测时间
2022-09-08 16:47:26 2022-09-08 16:47:28
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int mod = 998244353, o = 21, len = 1 << o;

int power(int a, int n) {
  int tp = 1;
  while (n) {
    if (n & 1)
      tp = 1ll *tp * a % mod;
    a = 1ll * a * a % mod, n >>= 1;
  }
  return tp;
}

typedef unsigned long long u64;
int w[len], r[len], up, l;

void init() {
  const int w0 = power(3, (mod - 1) >> o);
  w[len >> 1] = 1;
  for (int i = (len >> 1) + 1; i != len; i++)
    w[i] = 1ll * w[i - 1] * w0 % mod;
  for (int i = (len >> 1) - 1; i; i--)
    w[i] = w[i << 1];
  for (int i = 0; i != len; i++)
    r[i] = (r[i >> 1] >> 1) | ((i & 1) << (o - 1));
}

void ntt(int *a, int n, bool op) {
  static u64 t[len];
  const int b = 2;
  for (int op = 0; op != b; op++)
    for (int i = op; i < n; i += b)
      t[i] = a[r[i]];
  for (int l = 1; l != n; l <<= 1) {
    int *k = w + l;
    for (u64 *f = t; f != t + n; f += l)
      for (int *j = k; j != k + l; j++, f++) {
        u64 x = *f;
        int y = f[l] * *j % mod;
        f[l] = x + mod - y, *f += y;
      }
  }
  if (op) {
    for (int i = 0, x = mod - (mod >> l); i != n; i++)
      a[i] = t[i] * x % mod;
    reverse(a + 1, a + n);
  } else
    for (int i = 0; i != n; i++)
      a[i] = t[i] % mod;
}

int pre(int n) {
  l = 32 - __builtin_clz(n);
  return up = 1 << l;
}

void poly_multiply(unsigned *f, int n, unsigned *g, int m, unsigned *h) {
  static int x[len], y[len];
  init();
  memcpy(x, f, (n + 1) << 2), memcpy(y, g, (m + 1) << 2);
  pre(n + m), ntt(x, up, 0), ntt(y, up, 0);
  for (int i = 0; i != up; i++)
    x[i] = 1ll * x[i] * y[i] % mod;
  ntt(x, up, 1);
  memcpy(h, x, (n + m + 1) << 2);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1206.065 ms55 MB + 680 KBAcceptedScore: 100


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