提交记录 12468


用户 题目 状态 得分 用时 内存 语言 代码长度
fa_555 1002i. 【模板题】多项式乘法 Accepted 100 24.679 ms 8088 KB C++11 2.32 KB
提交时间 评测时间
2020-04-07 16:22:35 2020-08-01 02:55:26
#include<algorithm>
#include<cmath>
#include<cstdio>

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

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

  void flush() {
    fwrite(obuf, 1, p3 - obuf, stdout), p3 = obuf;
  }

  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;
  }

  IO operator<<(char n) {
    if (p3 - obuf == (1 << 20 | 1)) flush();
    *p3++ = n;
    return *this;
  }

  template<typename T>
  IO operator<<(T n) {
    static int stk[41];
    int top = 0;
    do stk[top++] = n % 10 + 48; while (n /= 10);
    while (top) *this << char(stk[--top]);
    return *this;
  }
} cin, cout;

constexpr double pi = acos(-1.);

int N, M, lim, l, to[1<<21|1];

struct Complex {
  double x, y;

  Complex() {}

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

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

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

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

void FFT(Complex *a, int type) {
  for (int i = 0; i <= lim; ++i)
    if (i < to[i]) std::swap(a[i], a[to[i]]);
  Complex rt, w, t1, t2;
  for (int m = 1; m < lim; m <<= 1) {
    rt = Complex(cos(pi / m), type * sin(pi / m));
    for (int j = 0; j < lim; 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 <= lim; ++i)
      a[i].x /= lim, a[i].y /= lim;
}

int main() {
  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(F, 1);
  for (int i = 0; i <= lim; ++i)
    F[i] = F[i] * F[i];
  FFT(F, -1);
  for (int i = 0; i <= N + M; ++i)
    cout << int(F[i].y / 2 + 0.5) << ' ';
  cout.flush();
  return 0;
}


CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #18.18 us28 KBAcceptedScore: 0

Subtask #1 Testcase #224.562 ms7 MB + 840 KBAcceptedScore: 100

Subtask #1 Testcase #310.458 ms3 MB + 272 KBAcceptedScore: 0

Subtask #1 Testcase #410.594 ms3 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #58.75 us28 KBAcceptedScore: 0

Subtask #1 Testcase #67.87 us28 KBAcceptedScore: 0

Subtask #1 Testcase #78.2 us28 KBAcceptedScore: 0

Subtask #1 Testcase #823.795 ms7 MB + 508 KBAcceptedScore: 0

Subtask #1 Testcase #923.775 ms7 MB + 508 KBAcceptedScore: 0

Subtask #1 Testcase #1022.925 ms7 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #1124.679 ms7 MB + 920 KBAcceptedScore: 0

Subtask #1 Testcase #1221.396 ms6 MB + 168 KBAcceptedScore: 0

Subtask #1 Testcase #137.45 us28 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-04 11:44:43 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用