提交记录 12377


用户 题目 状态 得分 用时 内存 语言 代码长度
zhengjiarui 1002i. 【模板题】多项式乘法 Accepted 100 25.465 ms 6072 KB C++11 3.33 KB
提交时间 评测时间
2020-03-31 21:46:14 2020-08-01 02:54:42
#pragma GCC optimize( "unroll-loops" )
#pragma GCC optimize( "O2" )
#include <bits/stdc++.h>

#define IL inline
#define CT const
#define RG register
#define TT template <typename Ty>

namespace io
{
const int MaxBuff = 1 << 24, MaxOut = 1 << 24;
char b[MaxBuff], *S = b, *T = b, buff[MaxOut], *iter = buff;
FILE *_IN = stdin, *_OUT = stdout;
IL char gc() { return S == T && (T = (S = b) + fread(b, 1, MaxBuff, _IN), S == T) ? 0 : *S++; }
IL void pc(const char s) { *iter++ = s; }
IL void fflush() { fwrite(buff, 1, iter - buff, _OUT), iter = buff, fclose(_IN), fclose(_OUT); }
} // namespace io

TT IL Ty max(CT Ty &a, CT Ty &b) { return a > b ? a : b; }
TT IL Ty min(CT Ty &a, CT Ty &b) { return a < b ? a : b; }
TT IL void cmax(Ty &a, CT Ty &b) { if (b > a) a = b; }
TT IL void cmin(Ty &a, CT Ty &b) { if (b < a) a = b; }
TT IL void swap(Ty &a, Ty &b) { Ty t = a; a = b; b = t; }
TT IL void swap(Ty *&a, Ty *&b) { Ty *t = a; a = b; b = t; }

TT IL void read(Ty &t)
{
    t = 0;
    int f = 1;
    RG char ch = io::gc();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = io::gc();
    }
    do
    {
        t = t * 10 + ch - '0';
        ch = io::gc();
    } while (ch >= '0' && ch <= '9');
    t *= f;
}

TT IL void write(Ty x)
{
    if (x < 0)
        io::pc('-');
    if (x > 9)
        write(x / 10);
    io::pc(x % 10 + '0');
}

typedef long long ll;
const int wcz = 998244353;
const int N = 1e6 + 5;

IL int addint( int x ) { return x >= wcz ? x - wcz : x; }
IL int addint( int x, int y ) { return addint(x + y); }
IL int qpow( int a, int b )
{
	int res = 1;
	for ( ; b; b >>= 1, a = ((ll)a * a) % wcz )
		if ( b & 1 ) res = ((ll)res * a) % wcz;
	return res;
}

namespace poly
{
int w[N * 4];

void dit(int n, int *a)
{
    for (int m = 1; m < n; m <<= 1)
    {
        int root = qpow(3, (wcz - 1) / (m << 1));
        w[0] = 1;
        for (int i = 1; i < m; ++i)
            w[i] = ((ll)w[i - 1] * root) % wcz;
        for (int i = 0; i < n; i += m << 1)
            for (int r = i; r < i + m; ++r)
            {
                int tmp = ((ll)w[r - i] * a[r + m]) % wcz;
                a[r + m] = addint(a[r], wcz - tmp);
                a[r] = addint(a[r], tmp);
            }
    }
}

void dif(int n, int *a)
{
    for (int m = n; m >>= 1;)
    {
        int root = qpow(3, wcz - 1 - (wcz - 1) / (m << 1));
        w[0] = 1;
        for (int i = 1; i < m; ++i)
            w[i] = ((ll)w[i - 1] * root) % wcz;
        for (int i = 0; i < n; i += m << 1)
            for (int r = i; r < i + m; ++r)
            {
                int tmp = addint(a[r], wcz - a[r + m]);
                a[r] = addint(a[r], a[r + m]);
                a[r + m] = ((ll)w[r - i] * tmp) % wcz;
            }
    }
}

void convolute(int n, int *a, int *b, int *out)
{
    dif(n, a);
    dif(n, b);
    unsigned long long inv_n = qpow(n, wcz - 2);
    for (int i = 0; i < n; ++i)
        out[i] = (((ll)inv_n * a[i]) % wcz * b[i]) % wcz;
    dit(n, out);
}
} // namespace poly

int n, m, a[N * 4], b[N * 4];

int main()
{
    read(n), read(m);
    ++n, ++m;
    for (int i = 0; i < n; ++i)
        read(a[i]);
    for (int i = 0; i < m; ++i)
        read(b[i]);
    int n2 = 1;
    while (m + n >= n2)
        n2 <<= 1;
    poly::convolute(n2, a, b, a);
    for (int i = 0; i < n + m - 1; ++i)
        write(a[i]), io::pc(' ');
    io::pc('\n');
    io::fflush();
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #135.06 us56 KBAcceptedScore: 0

Subtask #1 Testcase #224.822 ms5 MB + 788 KBAcceptedScore: 100

Subtask #1 Testcase #39.951 ms2 MB + 40 KBAcceptedScore: 0

Subtask #1 Testcase #49.943 ms2 MB + 20 KBAcceptedScore: 0

Subtask #1 Testcase #542.54 us56 KBAcceptedScore: 0

Subtask #1 Testcase #635.76 us56 KBAcceptedScore: 0

Subtask #1 Testcase #737.53 us56 KBAcceptedScore: 0

Subtask #1 Testcase #823.682 ms5 MB + 184 KBAcceptedScore: 0

Subtask #1 Testcase #923.679 ms5 MB + 184 KBAcceptedScore: 0

Subtask #1 Testcase #1022.558 ms4 MB + 608 KBAcceptedScore: 0

Subtask #1 Testcase #1125.465 ms5 MB + 952 KBAcceptedScore: 0

Subtask #1 Testcase #1220.336 ms3 MB + 708 KBAcceptedScore: 0

Subtask #1 Testcase #1335.44 us56 KBAcceptedScore: 0


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