提交记录 9125


用户 题目 状态 得分 用时 内存 语言 代码长度
FFjet 1002i. 【模板题】多项式乘法 Accepted 100 26.133 ms 9768 KB C++ 2.19 KB
提交时间 评测时间
2019-04-12 12:52:13 2020-08-01 01:32:37
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int MAXN = 1e6 + 10;
#define M_PI		3.14159265358979323846
struct CP
{
	double real, imaginary; 
	CP() { }
	inline CP(const double &a, const double &b): real(a), imaginary(b) { }
	inline CP operator + (const CP &r) const {return CP(real + r.real, imaginary + r.imaginary);}
	inline CP operator - (const CP &r) const {return CP(real - r.real, imaginary - r.imaginary);}
	inline CP operator * (const CP &r) const {return CP(real * r.real - imaginary * r.imaginary, real * r.imaginary + imaginary * r.real);}	
	inline CP conj() {return CP(real, -imaginary);}
};
CP a[MAXN], b[MAXN], t;
inline void _read(int &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
inline void print(int x)
{
	if (x == 0) return putchar(48), void();
	register int len = 0;int dg[20];
	while (x) dg[++len] = x % 10, x /= 10;
	for (register int i = len; i >= 1; i--) putchar(dg[i] + 48);
}
inline void swap(CP &a, CP &b)
{
	t = a, a = b, b = t;
}

inline void FFT(CP *a, const int &n, const int &f)
{
	for (register int i = 0, j = 0; i < n; ++i)
	{
		if (i > j) swap(a[i], a[j]);
		for (register int k = n >> 1; (j ^= k) < k; k >>= 1);
	}
	for (register int i = 1; i < n; i <<= 1)
	{
		CP wn(cos(M_PI / i), f * sin(M_PI / i));
		for (register int j = 0; j < n; j += i << 1)
		{
			CP w(1, 0);
			for (register int k = 0; k < i; ++k, w = w * wn)
			{
				CP x = a[j + k], y = w * a[i + j + k];
				a[j + k] = x + y, a[i + j + k] = x - y; 
			}
		}
	}
	if (f == -1) for (register int i = 0; i < n; ++i) a[i].real /= (double)n;
}

int n, m;
int main()
{
	_read(n), _read(m);
	for (register int i = 0, x; i <= n; ++i) _read(x), a[i].real = x;
	for (register int i = 0, x; i <= m; ++i) _read(x), a[i].imaginary = x;
	for (m += n, n = 1; n <= m; n <<= 1);
	FFT(a, n, 1);
	CP Q(0, -0.25);
	for (register int i = 0, j; i < n; ++i) j = (n - i) & (n - 1), b[i] = (a[i] * a[i] - (a[j] * a[j]).conj()) * Q;
	FFT(b, n, -1);
	for (register int i = 0; i <= m; ++i) print(int(b[i].real + 0.2)), putchar(' ');
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #135.78 us44 KBAcceptedScore: 0

Subtask #1 Testcase #225.696 ms9 MB + 472 KBAcceptedScore: 100

Subtask #1 Testcase #311.047 ms4 MB + 324 KBAcceptedScore: 0

Subtask #1 Testcase #411.103 ms4 MB + 312 KBAcceptedScore: 0

Subtask #1 Testcase #536.58 us44 KBAcceptedScore: 0

Subtask #1 Testcase #636.07 us44 KBAcceptedScore: 0

Subtask #1 Testcase #734.68 us44 KBAcceptedScore: 0

Subtask #1 Testcase #825.006 ms9 MB + 204 KBAcceptedScore: 0

Subtask #1 Testcase #924.889 ms9 MB + 204 KBAcceptedScore: 0

Subtask #1 Testcase #1023.912 ms8 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #1126.133 ms9 MB + 552 KBAcceptedScore: 0

Subtask #1 Testcase #1222.288 ms8 MB + 432 KBAcceptedScore: 0

Subtask #1 Testcase #1333.92 us44 KBAcceptedScore: 0


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