提交记录 20458


用户 题目 状态 得分 用时 内存 语言 代码长度
konjaklaf 1002i. 【模板题】多项式乘法 Accepted 100 64.913 ms 9852 KB C++ 1.99 KB
提交时间 评测时间
2023-10-29 19:37:52 2023-10-29 19:38:17
#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef long double LD;
typedef long long LL;
typedef double db;
const int N = 3e6 + 5;
const LL P = 998244353, G = 3, Gi = 332748118;
void add(LL &x, LL y) { (x += P + y % P) %= P; }
LL Pow(LL x, LL y) {
    LL res = 1;
    for (; y; y >>= 1, x = x * x % P)
        if (y & 1) res = res * x % P;
    return res;
}
int rev[N];
struct poly : vector<LL> {
    using vector::vector;
    using vector::operator[];
    void clr() { clear(), shrink_to_fit(); }
    void set(int n) { resize(n); }
} ;
int pre(int n) {
    int deg = 1;
    while (deg < n) deg <<= 1;
    for (int i = 1; i < deg; i++)
        rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (deg >> 1));
    return deg;
}
void NTT(poly &a, int deg, int op) {
    a.set(deg);
    for (int i = 0; i < deg; i++)
        if (i < rev[i]) swap(a[i], a[rev[i]]);
    LL wn, w, x, y;
    for (int i = 1; i < deg; i <<= 1) {
        wn = Pow(op == 1 ? G : Gi, (P - 1) / (i << 1));
        for (int j = 0; j < deg; j += (i << 1)) {
            w = 1;
            for (int k = 0; k < i; k++) {
                x = a[j + k], y = w * a[i + j + k] % P;
                a[j + k] = (x + y) % P;
                a[i + j + k] = (x - y + P) % P;
                w = w * wn % P;
            }
        }
    }
    if (op == -1) {
        wn = Pow(deg, P - 2);
        for (LL &o : a) o = o * wn % P;
    }
}
poly operator * (poly f, poly g) {
    if (f.empty() || g.empty()) return {};
    int n = f.size() + g.size() - 1;
    int deg = pre(n);
    NTT(f, deg, 1), NTT(g, deg, 1);
    for (int i = 0; i < deg; i++)
        f[i] = f[i] * g[i] % P;
    NTT(f, deg, -1);
    f.set(n);
    return f;
}
poly f, g;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    ++n, ++m;
    f.resize(n), g.resize(m);
    for (int i = 0; i < n; i++) cin >> f[i];
    for (int i = 0; i < m; i++) cin >> g[i];
    f = f * g;
    for (LL x : f) cout << x << ' ';
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #149.16 us64 KBAcceptedScore: 100

Subtask #1 Testcase #264.708 ms9 MB + 556 KBAcceptedScore: 0

Subtask #1 Testcase #330.39 ms4 MB + 384 KBAcceptedScore: 0

Subtask #1 Testcase #430.325 ms4 MB + 372 KBAcceptedScore: 0

Subtask #1 Testcase #544.33 us64 KBAcceptedScore: 0

Subtask #1 Testcase #643.69 us64 KBAcceptedScore: 0

Subtask #1 Testcase #743.2 us64 KBAcceptedScore: 0

Subtask #1 Testcase #860.255 ms8 MB + 772 KBAcceptedScore: 0

Subtask #1 Testcase #960.217 ms8 MB + 772 KBAcceptedScore: 0

Subtask #1 Testcase #1055.895 ms7 MB + 988 KBAcceptedScore: 0

Subtask #1 Testcase #1164.913 ms9 MB + 636 KBAcceptedScore: 0

Subtask #1 Testcase #1261.422 ms8 MB + 516 KBAcceptedScore: 0

Subtask #1 Testcase #1342.53 us64 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2025-09-13 04:03:43 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠