提交记录 16714


用户 题目 状态 得分 用时 内存 语言 代码长度
Saisyc 1002i. 【模板题】多项式乘法 Accepted 100 19.764 ms 6560 KB C++ 2.27 KB
提交时间 评测时间
2021-10-15 17:26:59 2021-10-15 17:27:03
#include <cstdio>
#include <cctype>
#include <algorithm>

namespace fastIO {
    const int SZ = 1 << 25;
    char ibuf[SZ], *p0 = ibuf, *p1 = ibuf;
    inline char getchar(void) { return p0 == p1 && (p1 = (p0 = ibuf) + fread(ibuf, 1, SZ, stdin), p0 == p1) ? EOF : *p0++; }
    char char_read; template<typename tpnm> void read(tpnm &val) {
		val = 0; do char_read = getchar(); while(!isdigit(char_read));
		do val = val * 10 + char_read - '0'; while(isdigit(char_read = getchar())); return;
    }
    char obuf[SZ], *p = obuf;
    inline void putchar(char char_write) { *p++ = char_write; return; }
    template<typename tpnm> void write(tpnm val) { if(val >= 10) write(val / 10); putchar(val % 10 + '0'); return; }
    template<typename tpnm> inline void write(tpnm a[], int sz) { for(int i = 0; i < sz; ++i) write(a[i]), putchar(' '); putchar('\n'); }
    void output(void) { fwrite(obuf, p - obuf, 1, stdout);}
};

const int N =     1 << 21;
const int p =    81 << 21 | 1;
const int g =  1167 << 12 | 1;
const int h = 11443 << 12 | 1;

inline int pow_modp(int a, int b) { int x = 1; for(; b; a = (long long)a * a % p, b >>= 1) if(b & 1) x = (long long)x * a % p; return x; }

int ntt_sup[N];
inline void  ntt(auto a[], int n, const int g) {
	auto b = ntt_sup; int _n = n >> 1;
	for(int i = 1, w = pow_modp(g, (p - 1) / n); i < n; i <<= 1, w = (long long)w * w % p, std :: swap(a, b))
		for(int j = 0, *k = a, *_k = a + _n, _w = 1; j != n; j += i << 1, _w = (long long)_w * w % p)
			for(int _j = j; _j != j + i; ++_j, ++k, ++_k)
				b[_j] = *k + *_k < 0 ? *k + *_k + p : *k + *_k - p, b[_j + i] = (long long)(*k - *_k) * _w % p;
	if(b != ntt_sup) std :: copy(a, a + n, b);
}
inline void poly_mul(auto a[], auto b[], int n) {
	ntt(a, n, g), ntt(b, n, g); for(int i = 0; i < n; ++i) a[i] = (long long)a[i] * b[i] % p; ntt(a, n, h);
	int inv_n = pow_modp(n, p - 2); for(int i = 0; i < n; ++i) a[i] = (long long)a[i] * inv_n % p;
	for(int i = 0; i < n; ++i) a[i] = a[i] < 0 ? a[i] + p : a[i];
}

int n, n_a, n_b;
int a[N], b[N];

int main(void) {
	fastIO :: read(n_a), fastIO :: read(n_b); for(n = 1; n <= n_a + n_b; n <<= 1);
	for(int i = 0; i <= n_a; ++i) fastIO :: read(a[i]);
	for(int i = 0; i <= n_b; ++i) fastIO :: read(b[i]);
	poly_mul(a, b, n);
	fastIO :: write(a, n_a + n_b + 1), fastIO :: output();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #17.68 us32 KBAcceptedScore: 0

Subtask #1 Testcase #219.512 ms6 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #38.271 ms2 MB + 276 KBAcceptedScore: 100

Subtask #1 Testcase #48.326 ms2 MB + 256 KBAcceptedScore: 0

Subtask #1 Testcase #59.5 us32 KBAcceptedScore: 0

Subtask #1 Testcase #69.1 us32 KBAcceptedScore: 0

Subtask #1 Testcase #78.02 us32 KBAcceptedScore: 0

Subtask #1 Testcase #818.718 ms5 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #918.707 ms5 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #1017.923 ms5 MB + 72 KBAcceptedScore: 0

Subtask #1 Testcase #1119.764 ms6 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #1216.568 ms4 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #137.5 us32 KBAcceptedScore: 0


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