提交记录 12690


用户 题目 状态 得分 用时 内存 语言 代码长度
fa_555 1002i. 【模板题】多项式乘法 Accepted 100 40.16 ms 7088 KB C++11 1.89 KB
提交时间 评测时间
2020-05-05 23:07:11 2020-08-01 02:57:40
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>

static char ibuf[1<<20|1], *p1 = ibuf, *p2 = ibuf;

struct IO {
  char gc() {
    return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20 | 1, stdin)) ? EOF : *p1++;
  }

  template<typename T>
  IO operator>>(T &n) {
    n = 0; char c = gc();
    while (c < '0' || c > '9') c = gc();
    while (c >= '0' && c <= '9') n = n * 10 + (c ^ 48), c = gc();
    return *this;
  }
} cin;

struct Complex {
  double x, y;

  Complex() {}

  Complex(double X, double Y): x(X), y(Y) {}

  Complex operator+(Complex rhs) {
    return Complex(x + rhs.x, y + rhs.y);
  }

  Complex operator-(Complex rhs) {
    return Complex(x - rhs.x, y - rhs.y);
  }

  Complex operator*(Complex rhs) {
    return Complex(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
  }
} F[1<<21|1];

constexpr double pi = acos(-1.);

int to[1<<21|1];

void FFT(int N, Complex *a, int type) {
  for (int i = 0; i < N; ++i)
    if (i < to[i]) std::swap(a[i], a[to[i]]);

  Complex rt, w, t1, t2;
  for (int m = 1; m < N; m <<= 1) {
    rt = Complex(cos(pi / m), type * sin(pi / m));
    for (int j = 0; j < N; j += m << 1) {
      w = Complex(1, 0);
      for (int k = 0; k < m; ++k, w = w * rt) {
        t1 = a[j | k], t2 = w * a[j | k | m];
        a[j | k] = t1 + t2, a[j | k | m] = t1 - t2;
      }
    }
  }

  if (type == -1)
    for (int i = 0; i < N; ++i)
      a[i].x /= N, a[i].y /= N;
}

int main() {
  int N, M, lim, l;

  cin >> N >> M;
  for (lim = 1, l = -1; lim <= N + M; lim <<= 1, ++l);
  for (int i = 0; i < lim; ++i)
    to[i] = (to[i >> 1] >> 1) | ((i & 1) << l);
  for (int i = 0, t; i <= N; ++i)
    cin >> t, F[i].x = t;
  for (int i = 0, t; i <= M; ++i)
    cin >> t, F[i].y = t;
  FFT(lim, F, 1);
  for (int i = 0; i < lim; ++i)
    F[i] = F[i] * F[i];
  FFT(lim, F, -1);
  for (int i = 0; i <= N + M; ++i)
    std::cout << int(F[i].y / 2 + 0.5) << ' ';
  return 0;
}


CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #135.84 us48 KBAcceptedScore: 0

Subtask #1 Testcase #239.825 ms6 MB + 864 KBAcceptedScore: 100

Subtask #1 Testcase #318.033 ms3 MB + 12 KBAcceptedScore: 0

Subtask #1 Testcase #418.026 ms3 MBAcceptedScore: 0

Subtask #1 Testcase #537.62 us48 KBAcceptedScore: 0

Subtask #1 Testcase #635.77 us48 KBAcceptedScore: 0

Subtask #1 Testcase #735.15 us48 KBAcceptedScore: 0

Subtask #1 Testcase #836.384 ms6 MB + 532 KBAcceptedScore: 0

Subtask #1 Testcase #936.366 ms6 MB + 532 KBAcceptedScore: 0

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

Subtask #1 Testcase #1140.16 ms6 MB + 944 KBAcceptedScore: 0

Subtask #1 Testcase #1236.686 ms5 MB + 824 KBAcceptedScore: 0

Subtask #1 Testcase #1334.22 us48 KBAcceptedScore: 0


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