提交记录 11822


用户 题目 状态 得分 用时 内存 语言 代码长度
zhengjiarui 1002i. 【模板题】多项式乘法 Accepted 100 48.234 ms 8284 KB C++11 4.63 KB
提交时间 评测时间
2020-02-14 22:44:31 2020-08-01 02:48:20
/**********************************************************
 * By Jerry Zheng
 * 
 * Get more points as possible.
 * Is the understanding of the statement correct?
 * If Subtask #2 is too hard, why not try Subtask #3?
 * 
 * Think twice, code once.
 * Are there any counterexamples to your algo?
 * Is the sol too heavy to debug?
 * Is the Time & Meomry complexity correct?
 * 
 * DON'T MAKE STUPID MISTAKES!!!!!
 * file-IO? DEBUG output? array size?
 * boundaries? long long?
 *
                         _ooOoo_
                        o8888888o
                        88" . "88
                        (| -_- |)
                        O\  =  /O
                     ____/`---'\____
                   .'  \|     |//  `.
                  /  \|||  :  |||//  \
                 /  _||||| -:- |||||-  \
                 |   | \  -  /// |   |
                 | \_|  ''\---/''  |   |
                 \  .-\__  `-`  ___/-. /
               ___`. .'  /--.--\  `. . __
            ."" '<  `.___\_<|>_/___.'  >'"".
           | | :  `- \`.;`\ _ /`;.`/ - ` : | |
           \  \ `-.   \_ __\ /__ _/   .-` /  /
      ======`-.____`-.___\_____/___.-`____.-'======
                         `=---='
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 佛祖保佑        永无BUG
**********************************************************/
#include <bits/stdc++.h>

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

namespace io {
const int MaxBuff = 1 << 15, 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 ps(const char *s) { while (*s) *iter++ = *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');
}

const int N = 2e6 + 5;
const int wcz = 998244353;

namespace poly {
typedef long long ll;

IL int qpow(int a, int b) {
    int ans = 1;
    for (; b; b >>= 1, a = ((ll)a * a) % wcz)
        if (b & 1)
            ans = ((ll)ans * a) % wcz;
    return ans;
}

int n, rev[N * 4], w[N * 4], inv_w[N * 4];

void ntt(int *a) {
    for (int i = 0; i < n; ++i)
        if (i < rev[i])
            swap(a[i], a[rev[i]]);
    for (int step = 1, ws = n / 2; step < n; step *= 2, ws /= 2)
        for (int j = 0; j < n; j += step * 2)
            for (int k = j, wn = 0; k < j + step; ++k, wn += ws) {
                int x = a[k], y = ((ll)a[k + step] * w[wn]) % wcz;
                a[k] = (x + y) % wcz, a[k + step] = (x - y + wcz) % wcz;
            }
}

void intt(int* a) {
    for (int i = 0; i < n; ++i)
        if (i < rev[i])
            swap(a[i], a[rev[i]]);
    for (int step = 1, ws = n / 2; step < n; step *= 2, ws /= 2)
        for (int j = 0; j < n; j += step * 2)
            for (int k = j, wn = 0; k < j + step; ++k, wn += ws) {
                int x = a[k], y = ((ll)a[k + step] * inv_w[wn]) % wcz;
                a[k] = (x + y) % wcz, a[k + step] = (x - y + wcz) % wcz;
            }
    for (int i = 0, inv = qpow(n, wcz - 2); i < n; i++)
        a[i] = ((ll)a[i] * inv) % wcz;
}

IL void init_n(int nn) {
    for (n = 1; n <= nn; n <<= 1) ;
    for (int i = 0; i < n; ++i)
        rev[i] = (i & 1) ? (rev[i - 1] + n / 2) : (rev[i / 2] / 2);
    int gn = qpow(3, (wcz - 1) / n), gm = qpow(gn, wcz - 2);
    for (int i = 0, j1 = 1, j2 = 1; i < n; ++i)
        w[i] = j1, j1 = ((ll)j1 * gn) % wcz, inv_w[i] = j2,
        j2 = ((ll)j2 * gm) % wcz;
}
} // namespace poly

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

int main() {
	read(n), read(m);
	for (int i = 0; i <= n; ++i) read(a[i]);
	for (int i = 0; i <= m; ++i) read(b[i]);
    poly::init_n(n + m + 1);
    poly::ntt(a), poly::ntt(b);
    for (int i = 0; i < poly::n; ++i) a[i] = ((long long)a[i] * b[i]) % wcz;
    poly::intt(a);
    int flag = 1;
    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 #136.59 us68 KBAcceptedScore: 0

Subtask #1 Testcase #247.597 ms7 MB + 956 KBAcceptedScore: 0

Subtask #1 Testcase #316.332 ms3 MB + 144 KBAcceptedScore: 100

Subtask #1 Testcase #416.394 ms3 MB + 124 KBAcceptedScore: 0

Subtask #1 Testcase #538.21 us68 KBAcceptedScore: 0

Subtask #1 Testcase #637.29 us68 KBAcceptedScore: 0

Subtask #1 Testcase #737.05 us68 KBAcceptedScore: 0

Subtask #1 Testcase #846.455 ms7 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #946.428 ms7 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #1045.295 ms6 MB + 904 KBAcceptedScore: 0

Subtask #1 Testcase #1148.234 ms8 MB + 92 KBAcceptedScore: 0

Subtask #1 Testcase #1243.053 ms5 MB + 872 KBAcceptedScore: 0

Subtask #1 Testcase #1336.41 us68 KBAcceptedScore: 0


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