提交记录 7956


用户 题目 状态 得分 用时 内存 语言 代码长度
1695651 1002i. 【模板题】多项式乘法 Compile Error 0 0 ns 0 KB C++ 1.45 KB
提交时间 评测时间
2019-01-25 23:08:29 2020-08-01 01:10:36
#include <bits/stdc++.h>
using namespace std;
typedef complex <double> cp;
const int N = 1e6 + 10;
const double PI = acos(-1);
int n = 1, lena, lenb, ans[N];
cp a[N], b[N], omg[N], inv[N];
inline void init(){
    for (int i = 0; i < n; i++){
        omg[i] = cp(cos(2 * PI * i / n), sin(2 * PI * i / n));
        inv[i] = conj(omg[i]);
    }
}
inline void fft(cp *a, cp *omg){
    int lim = 0;
    while ((1 << lim) < n) ++lim;
    for (int i = 0; i < n; i++){
        int t = 0;
        for (int j = 0; j < lim; j++)
            if (i & (1 << j)) t |= (1 << (lim - j - 1));
        if (t < i) swap(a[t], a[i]);
    }
    for (int l = 2; l <= n; l <<= 1){
        int m = l / 2;
        for (cp *p = a; p != a + n; p += l){
            for (int i = 0; i < m; i++){
                cp t = omg[n / l * i] * p[i + m];
                p[i + m] = p[i] - t;
                p[i] += t;
            }
        }
    }
}
int main(){
    scanf("%d %d", &lena, &lenb);
    ++lena, ++lenb;
    int x;
    for (int i = 0; i < lena; i++){
        scanf("%d", &x);
        a[i].real(x);
    }
    for (int i = 0; i < lenb; i++){
        scanf("%d", &x);
        b[i].real(x);
    }
    while (n < lena + lenb) n <<= 1;
    init();
    fft(a, omg);
    fft(b, omg);
    for (int i = 0; i < n; i++) a[i] *= b[i];
    fft(a, inv);
    for (int i = 0; i < n; i++)
        a[i].real() = abs(a[i].real() / n);
    for (int i = 0; i < lena + lenb - 1; i++) printf("%.0lf ", a[i].real());
    return 0;
}

CompilationN/AN/ACompile ErrorScore: N/A


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-23 14:40:20 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用