提交记录 16845


用户 题目 状态 得分 用时 内存 语言 代码长度
Saisyc 1002i. 【模板题】多项式乘法 Accepted 100 30.519 ms 13096 KB C++ 2.42 KB
提交时间 评测时间
2021-10-25 16:03:16 2021-10-25 16:03:20
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cmath>

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; void read(auto &val) {
		val = 0; do char_read = getchar(); while(!isdigit(char_read));
		do val = val * 10 + char_read - '0'; while(isdigit(char_read = getchar()));
    }
    char obuf[SZ], *p = obuf;
    inline void putchar(char char_write) { *p++ = char_write; }
    void write(auto val) { if(val >= 10) write(val / 10); putchar(val % 10 + '0'); }
    inline void write(auto 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 double PI = acos(-1);

struct CMPLX {
	double real, imag;
	CMPLX operator + (CMPLX z) const { return (CMPLX){ real + z.real, imag + z.imag}; }
	CMPLX operator - (CMPLX z) const { return (CMPLX){ real - z.real, imag - z.imag}; }
	CMPLX operator * (CMPLX z) const { return (CMPLX){ real * z.real - imag * z.imag, real * z.imag + imag * z.real}; }
};

CMPLX fft_sup[N];
inline void fft(auto a[], int n, CMPLX w) {
	auto b = fft_sup, j = a, _j = a; int i, k, _k; auto _w = w;
	for(i = 1; i < n; i <<= 1, w = w * w, std :: swap(a, b))
		for(k = 0, j = a, _j = a + (n >> 1), _w = (CMPLX){ 1, 0 }; k != n; k += i, _w = _w * w)
			for(_k = k, k += i; _k != k; ++j, ++_j, ++_k)
				b[_k] = *j + *_j,
				b[_k + i] = (*j - *_j) * _w;
	if(b != fft_sup) std :: copy(a, a + n, b);
}
CMPLX c[N];
inline void poly_mul(auto a[], auto b[], int n) {
	for(int i = 0; i < n; ++i) c[i].real = a[i], c[i].imag = b[i]; fft(c, n, (CMPLX){ cos(PI / n * 2), sin(PI / n * 2) });
	for(int i = 0; i < n; ++i) c[i] = c[i] * c[i]; fft(c, n, (CMPLX){ cos(PI / n * 2), -sin(PI / n * 2) });
	double _n = 0.5 / n; for(int i = 0; i < n; ++i) a[i] = c[i].imag * _n + 0.5;
	
	for(int i = 0; i < n; ++i) c[i] = c[i] * c[i];
	for(int i = 0; i < n; ++i) c[i] = c[i] * c[i];
	for(int i = 0; i < n; ++i) c[i] = c[i] * c[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 #18.5 us36 KBAcceptedScore: 0

Subtask #1 Testcase #230.252 ms12 MB + 644 KBAcceptedScore: 0

Subtask #1 Testcase #310.716 ms5 MB + 668 KBAcceptedScore: 100

Subtask #1 Testcase #410.732 ms5 MB + 260 KBAcceptedScore: 0

Subtask #1 Testcase #59.58 us36 KBAcceptedScore: 0

Subtask #1 Testcase #69.39 us36 KBAcceptedScore: 0

Subtask #1 Testcase #79.19 us36 KBAcceptedScore: 0

Subtask #1 Testcase #829.422 ms12 MB + 44 KBAcceptedScore: 0

Subtask #1 Testcase #929.431 ms11 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #1028.679 ms11 MB + 332 KBAcceptedScore: 0

Subtask #1 Testcase #1130.519 ms12 MB + 808 KBAcceptedScore: 0

Subtask #1 Testcase #1227.146 ms10 MB + 564 KBAcceptedScore: 0

Subtask #1 Testcase #138.66 us32 KBAcceptedScore: 0


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