提交记录 7011


用户 题目 状态 得分 用时 内存 语言 代码长度
negiizhao 1002i. 【模板题】多项式乘法 Accepted 100 20.742 ms 12704 KB C++11 2.69 KB
提交时间 评测时间
2018-12-10 11:36:28 2020-08-01 00:57:10
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>

typedef long long int64;

struct IO_Tp
{
	const static int _I_Buffer_Size = 2 << 20;
	char _I_Buffer[_I_Buffer_Size], *_I_pos = _I_Buffer;
	
	const static int _O_Buffer_Size = 2 << 20;
	char _O_Buffer[_O_Buffer_Size], *_O_pos = _O_Buffer;
	
	IO_Tp()
	{
		fread(_I_Buffer, 1, _I_Buffer_Size, stdin);
	}
	
	~IO_Tp()
	{
		fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout);
	}
	
	IO_Tp &operator>>(int &res)
	{
		while (!isdigit(*_I_pos))
			++_I_pos;
		res = *_I_pos++ & 15;
		while (isdigit(*_I_pos))
			(res *= 10) += *_I_pos++ & 15;
		return *this;
	}
	
	IO_Tp &operator<<(int n)
	{
		static char _buf[10];
		char* _pos = _buf;
		do
			*_pos++ = '0' + n % 10;
		while (n /= 10);
		while (_pos != _buf)
			*_O_pos++ = *--_pos;
		return *this;
	}
	
	IO_Tp &operator<<(char ch)
	{
		*_O_pos++ = ch;
		return *this;
	}
} IO;

constexpr double Pi = 3.1415926535897932384626433832795;
constexpr int Max_size = 1 << 18 | 5;

int size;
int bitrev[Max_size];
double c[Max_size], s[Max_size];

inline void init(int n)
{
	for (size = 1; size < n; size <<= 1)
		;
	for (int i = 0; i != size; ++i)
		bitrev[i] = bitrev[i >> 1] >> 1 | ((i & 1) * (size >> 1));
	size >>= 1;
	c[size] = 1, s[size] = 0;
	double pc = cos(Pi / size), ps = sin(Pi / size);
	for (int i = 1; i != size; ++i)
		c[size + i] = c[size + i - 1] * pc - s[size + i - 1] * ps, s[size + i] = s[size + i - 1] * pc + c[size + i - 1] * ps;
	for (int i = size - 1; i; --i)
		c[i] = c[i << 1], s[i] = s[i << 1];
	size <<= 1;
}

inline void DHT(double A[], int L)
{
	int shift = __builtin_ctz(size) - __builtin_ctz(L);
	for (int i = 0; i != L; ++i)
		if (i < bitrev[i] >> shift)
			std::swap(A[i], A[bitrev[i] >> shift]);
	for (int d = 1; d != L; d <<= 1)
		for (int i = 0; i != L; i += d << 1)
		{
			for (int j = d + 1, k = d + d - 1; j < k; ++j, --k)
			{
				double x = A[i + j], y = A[i + k];
				A[i + j] = c[j] * x + s[j] * y, A[i + k] = s[j] * x - c[j] * y;
			}
			for (int j = 0; j != d; ++j)
			{
				double x = A[i + j], y = A[i + d + j];
				A[i + j] = x + y, A[i + d + j] = x - y;
			}
		}
}

int N, M, L;
double A[Max_size], B[Max_size];

int main(int argc, char **argv)
{
	IO >> N >> M;
	for (int i = 0, x; i <= N; ++i)
		IO >> x, A[i] = x;
	for (int i = 0, x; i <= M; ++i)
		IO >> x, B[i] = x;
	
	for (L = 2; L <= N + M; L <<= 1)
		;
	init(L);
	
	DHT(A, L), DHT(B, L);
	A[0] = A[0] * B[0];
	for (int i = 1; i <= L >> 1; ++i)
	{
		double x = A[i] + A[L - i], y = A[i] - A[L - i];
		A[i] = (B[i] * x + B[L - i] * y) / 2, A[L - i] = (B[L - i] * x - B[i] * y) / 2;
	}
	DHT(A, L);
	for (int i = 0; i != L; ++i)
		A[i] /= L;
	
	for (int i = 0; i <= N + M; ++i)
		IO << static_cast<int>(A[i] + 0.5) << ' ';
	
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #113.13 us52 KBAcceptedScore: 0

Subtask #1 Testcase #220.543 ms12 MB + 256 KBAcceptedScore: 100

Subtask #1 Testcase #38.811 ms5 MB + 296 KBAcceptedScore: 0

Subtask #1 Testcase #48.859 ms5 MB + 276 KBAcceptedScore: 0

Subtask #1 Testcase #514.3 us52 KBAcceptedScore: 0

Subtask #1 Testcase #613.5 us52 KBAcceptedScore: 0

Subtask #1 Testcase #713.29 us52 KBAcceptedScore: 0

Subtask #1 Testcase #819.794 ms11 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #919.78 ms11 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #1018.994 ms11 MB + 72 KBAcceptedScore: 0

Subtask #1 Testcase #1120.742 ms12 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #1217.56 ms10 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #1313.32 us52 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-09 04:07:47 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠