提交记录 31257


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_260814 1002i. 【模板题】多项式乘法 Accepted 100 37.542 ms 5524 KB C++ 2.91 KB
提交时间 评测时间
2026-08-14 01:02:50 2026-08-14 01:02:55
// v1: baseline NTT mod 998244353, standard DIT with bitrev, fast IO
#include <cstdio>
#include <cstring>
#include <cstdlib>

typedef unsigned long long u64;
typedef long long i64;

const int MOD = 998244353;
const int G = 3;
const int MAXN = 1 << 18;

static int a[MAXN], b[MAXN];

static inline int modpow(int base, i64 e) {
    i64 r = 1, b = base % MOD;
    for (; e; e >>= 1) {
        if (e & 1) r = r * b % MOD;
        b = b * b % MOD;
    }
    return (int)r;
}

static void ntt(int *x, int n, bool inv) {
    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1) j ^= bit;
        j ^= bit;
        if (i < j) { int t = x[i]; x[i] = x[j]; x[j] = t; }
    }
    for (int len = 2; len <= n; len <<= 1) {
        int wlen = modpow(G, (MOD - 1) / len);
        if (inv) wlen = modpow(wlen, MOD - 2);
        int half = len >> 1;
        for (int i = 0; i < n; i += len) {
            i64 w = 1;
            int *y = x + i;
            for (int j = 0; j < half; j++) {
                int u = y[j];
                int v = (int)(y[j + half] * w % MOD);
                int s = u + v; if (s >= MOD) s -= MOD;
                int d = u - v; if (d < 0) d += MOD;
                y[j] = s;
                y[j + half] = d;
                w = w * wlen % MOD;
            }
        }
    }
    if (inv) {
        int ninv = modpow(n, MOD - 2);
        for (int i = 0; i < n; i++) x[i] = (int)((i64)x[i] * ninv % MOD);
    }
}

// fast input buffer
static const int BUFSZ = 1 << 20;
static char inbuf[BUFSZ];
static size_t inpos = 0, inlen = 0;

static inline int readbyte() {
    if (inpos >= inlen) {
        inlen = fread(inbuf, 1, BUFSZ, stdin);
        inpos = 0;
        if (inlen == 0) return -1;
    }
    return (unsigned char)inbuf[inpos++];
}

static inline int readint() {
    int c = readbyte();
    while (c == ' ' || c == '\n' || c == '\r' || c == '\t') c = readbyte();
    int x = 0;
    while (c >= '0' && c <= '9') {
        x = x * 10 + (c - '0');
        c = readbyte();
    }
    return x;
}

// fast output buffer
static char outbuf[1 << 21];
static size_t outpos = 0;

static inline void putc(char c) { outbuf[outpos++] = c; }

static inline void putint(int x) {
    if (x == 0) { putc('0'); return; }
    char tmp[12]; int t = 0;
    while (x) { tmp[t++] = '0' + (x % 10); x /= 10; }
    while (t) putc(tmp[--t]);
}

int main() {
    int n = readint();
    int m = readint();
    int na = n + 1;
    int nb = m + 1;
    for (int i = 0; i < na; i++) a[i] = readint();
    for (int i = 0; i < nb; i++) b[i] = readint();

    int size = 1;
    while (size < na + nb - 1) size <<= 1;

    ntt(a, size, false);
    ntt(b, size, false);
    for (int i = 0; i < size; i++) a[i] = (int)((i64)a[i] * b[i] % MOD);
    ntt(a, size, true);

    int outn = n + m + 1;
    for (int i = 0; i < outn; i++) {
        if (i) putc(' ');
        putint(a[i]);
    }
    putc('\n');
    fwrite(outbuf, 1, outpos, stdout);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110.93 us28 KBAcceptedScore: 100

Subtask #1 Testcase #237.386 ms5 MB + 240 KBAcceptedScore: 0

Subtask #1 Testcase #316.975 ms1 MB + 784 KBAcceptedScore: 0

Subtask #1 Testcase #417.035 ms1 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #59.12 us28 KBAcceptedScore: 0

Subtask #1 Testcase #68.74 us28 KBAcceptedScore: 0

Subtask #1 Testcase #78.44 us28 KBAcceptedScore: 0

Subtask #1 Testcase #836.787 ms4 MB + 664 KBAcceptedScore: 0

Subtask #1 Testcase #936.809 ms4 MB + 664 KBAcceptedScore: 0

Subtask #1 Testcase #1036.238 ms4 MB + 60 KBAcceptedScore: 0

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

Subtask #1 Testcase #1235.045 ms3 MB + 160 KBAcceptedScore: 0

Subtask #1 Testcase #137.31 us28 KBAcceptedScore: 0


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