提交记录 12992


用户 题目 状态 得分 用时 内存 语言 代码长度
dblark 1002i. 【模板题】多项式乘法 Accepted 100 53.297 ms 6668 KB C++11 2.00 KB
提交时间 评测时间
2020-07-17 19:41:53 2020-08-01 03:02:44
#include <cstdio>
#include <cstring>
#include <algorithm>
#define len 262144
#define p 998244353
#define g 3

namespace number {
    inline int add(int x, int y) { return (x += y) >= p ? x - p : x; }
    inline int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
    inline int mul(int x, int y) { return (long long)x * y % p; }
    inline int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }
}

using namespace number;

namespace poly {
    int N, l;
    int w[len], r[len], t[len];
    inline void init(int n) {
        N = 2, l = 1;
        while (N < n) N <<= 1, ++l;
        for (int i = 0; i < N; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
        int wn = power(g, (p - 1) >> l);
        w[N >> 1] = 1;
        for (int i = (N >> 1) + 1; i < N; ++i) w[i] = mul(w[i - 1], wn);
        for (int i = (N >> 1) - 1; i; --i) w[i] = w[i << 1];
    }
    inline void NTT(int *a, int n, int opt) {
        int shift = l - __builtin_ctz(n);
        for (int i = 0; i < n; ++i) t[r[i] >> shift] = a[i];
        memcpy(a, t, n << 2);
        for (int i = 1; i < n; i <<= 1)
            for (int j = 0; j < n; j += i << 1)
                for (int k = 0; k < i; ++k) {
                    int x = a[j + k], y = mul(a[i + j + k], w[i + k]);
                    a[j + k] = add(x, y);
                    a[i + j + k] = sub(x, y);
                }
        if (opt == -1) {
            int x = power(n, p - 2);
            for (int i = 0; i < n; ++i) a[i] = mul(a[i], x);
            std::reverse(a + 1, a + n);
        }
    }
}

int n, m;
int a[len], b[len];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i <= n; ++i) scanf("%d", a + i);
    for (int i = 0; i <= m; ++i) scanf("%d", b + i);
    poly::init(n + m + 1);
    poly::NTT(a, poly::N, 1);
    poly::NTT(b, poly::N, 1);
    for (int i = 0; i < poly::N; ++i) a[i] = mul(a[i], b[i]);
    poly::NTT(a, poly::N, -1);
    for (int i = 0; i <= n + m; ++i) printf("%d ", a[i]);
    puts("");
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110.54 us36 KBAcceptedScore: 0

Subtask #1 Testcase #252.739 ms6 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #324.281 ms2 MB + 828 KBAcceptedScore: 100

Subtask #1 Testcase #424.356 ms2 MB + 816 KBAcceptedScore: 0

Subtask #1 Testcase #511.87 us36 KBAcceptedScore: 0

Subtask #1 Testcase #611.61 us36 KBAcceptedScore: 0

Subtask #1 Testcase #711.47 us36 KBAcceptedScore: 0

Subtask #1 Testcase #847.247 ms6 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #946.948 ms6 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #1041.186 ms5 MB + 932 KBAcceptedScore: 0

Subtask #1 Testcase #1153.191 ms6 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #1253.297 ms5 MB + 404 KBAcceptedScore: 0

Subtask #1 Testcase #1310.71 us36 KBAcceptedScore: 0


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