提交记录 17475


用户 题目 状态 得分 用时 内存 语言 代码长度
aonynation 1002i. 【模板题】多项式乘法 Accepted 100 46.095 ms 97132 KB C++ 2.50 KB
提交时间 评测时间
2022-03-08 12:00:29 2022-03-08 12:00:33
#include <bits/stdc++.h>

#define file(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

#define Enter putchar('\n')
#define quad putchar(' ')

#define N 3000005

namespace IO {

template <class T>
inline void read(T &a);
template <class T, class ...rest>
inline void read(T &a, rest &...x);

template <class T>
inline void write(T x);

}

struct cp {
  double x, y;
  cp (double xx = 0, double yy = 0) {x = xx; y = yy;};

  friend cp operator +(cp p, cp q) {return cp(p.x + q.x, p.y + q.y);}
  friend cp operator -(cp p, cp q) {return cp(p.x - q.x, p.y - q.y);}
  friend cp operator *(cp p, cp q) {return cp(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);}
}a[N], b[N];

const double pi = 3.1415926535;

int n1, n2, n, rev[N], c[N];

inline void FFT(cp *a, int n, int inv) {
  int bit = 0;
  while ((1 << bit) < n) bit++;
  for (int i = 1; i < n; ++i) {
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
    if (i < rev[i])
      std::swap(a[rev[i]], a[i]);
  }
  for (int mid = 1; mid < n; mid <<= 1) {
    cp temp(cos(pi / mid), inv * sin(pi / mid));
    for (int i = 0; i < n; i += mid * 2) {
      cp omega(1,0);
      for (int j = 0; j < mid; ++j, omega = omega * temp) {
        cp x = a[i + j], y = omega * a[i + j + mid];
        a[i + j] = x + y;
        a[i + j + mid] = x - y;
      }
    }
  }
}

signed main(void) {
  // file("P3803");
  IO::read(n1, n2);
  n = std::max(n1, n2);
  for (int i = 0, num; i <= n1; ++i) IO::read(num), a[i].x = num;
  for (int i = 0, num; i <= n2; ++i) IO::read(num), b[i].x = num;
  n = n1 + n2;
  for (int i = 0; i <= 30; ++i)
    if ((1 << i) > n) {
      n = (1 << i);
      break;
    }

  FFT(a, n, 1); FFT(b, n, 1);
  for (int i = 0; i < n; ++i) a[i] = a[i] * b[i];
  FFT(a, n, -1);
  for (int i = 0; i <= n1 + n2; ++i)
    c[i] = (int)(a[i].x / n + 0.5);
  
  for (int i = 0; i <= n1 + n2; ++i)
    IO::write(c[i]), quad;
  Enter;
}

namespace IO {

template <class T>
inline void read(T &a) {
  T s = 0, t = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-')
    c = getchar();
  if (c == '-')
    c = getchar(), t = -1;
  while (c >= '0' && c <= '9')
    s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
  a = s * t;
}
template <class T, class ...rest>
inline void read(T &a, rest &...x) {
  read(a);
  read(x...);
}

template <class T>
inline void write(T x) {
  if (x == 0) putchar('0');
  if (x < 0) putchar('-'), x = -x;
  int top = 0, sta[55] = {0};
  while (x) 
    sta[++top] = x % 10, x /= 10;
  while (top)
    putchar(sta[top] + '0'), top--;
  return ;
}

}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110.79 ms91 MB + 612 KBAcceptedScore: 0

Subtask #1 Testcase #246.095 ms94 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #325.486 ms92 MB + 768 KBAcceptedScore: 100

Subtask #1 Testcase #425.365 ms92 MB + 756 KBAcceptedScore: 0

Subtask #1 Testcase #510.51 ms91 MB + 612 KBAcceptedScore: 0

Subtask #1 Testcase #610.257 ms91 MB + 612 KBAcceptedScore: 0

Subtask #1 Testcase #710.263 ms91 MB + 612 KBAcceptedScore: 0

Subtask #1 Testcase #844.773 ms94 MB + 392 KBAcceptedScore: 0

Subtask #1 Testcase #944.214 ms94 MB + 392 KBAcceptedScore: 0

Subtask #1 Testcase #1042.929 ms93 MB + 1016 KBAcceptedScore: 0

Subtask #1 Testcase #1145.893 ms94 MB + 876 KBAcceptedScore: 0

Subtask #1 Testcase #1240.209 ms93 MB + 756 KBAcceptedScore: 0

Subtask #1 Testcase #1310.632 ms91 MB + 608 KBAcceptedScore: 0


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