提交记录 9126


用户 题目 状态 得分 用时 内存 语言 代码长度
FFjet 1002i. 【模板题】多项式乘法 Accepted 100 26.444 ms 9768 KB C++ 2.22 KB
提交时间 评测时间
2019-04-12 12:53:02 2020-08-01 01:32:40
#pragma GCC optimize("Ofast")
#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 #134.89 us44 KBAcceptedScore: 0

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

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

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

Subtask #1 Testcase #537.05 us44 KBAcceptedScore: 0

Subtask #1 Testcase #635.23 us44 KBAcceptedScore: 0

Subtask #1 Testcase #736.24 us44 KBAcceptedScore: 0

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

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

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

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

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

Subtask #1 Testcase #1334.02 us44 KBAcceptedScore: 0


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