提交记录 8243


用户 题目 状态 得分 用时 内存 语言 代码长度
Conical 1002i. 【模板题】多项式乘法 Accepted 100 24.884 ms 27972 KB C++ 2.39 KB
提交时间 评测时间
2019-02-05 20:45:37 2020-08-01 01:14:30
#include <bits/stdc++.h>
using namespace std;

namespace io 
{
	const int L = (1 << 22) + 1;
	char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, L, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout); oS = obuf; }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	template <class I> inline void gi (I & x)
	{
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	template <class I> inline void print (I x)
	{
		if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0', x /= 10;
		while (qr) pc (qu[qr --]);
	}
	struct IOC { ~ IOC () { flush (); } } _ioc_;
}
using io :: gi;
using io :: pc;
using io :: print;

const double pi (acos(-1));
const int MaxN(500003);
int rev[MaxN];

struct comp_t
{
	double x, y;
	comp_t(double _x = 0, double _y = 0) : x(_x), y(_y) { }
	inline comp_t operator + (const comp_t &T)
	{ return comp_t(x + T.x, y + T.y); }
	inline comp_t operator - (const comp_t &T)
	{ return comp_t(x - T.x, y - T.y); }
	inline comp_t operator * (const comp_t &T)
	{ return comp_t(x * T.x - y * T.y, x * T.y + y * T.x); }
	inline comp_t conj()
	{ return comp_t(x, -y); }
}A[MaxN], F[MaxN];

void dft(comp_t *a, int n, int f)
{
	for(int i = 1; i < n; i++)
		if(i < rev[i])
			swap(a[i], a[rev[i]]);
	for(int l = 1; l < n; l <<= 1)
	{
		comp_t wn(cos(pi / l), sin(pi / l) * f);
		static comp_t w[MaxN];
		w[0] = 1.0;
		for(int i = 1; i < l; i++)
			w[i] = w[i - 1] * wn;
		for(int i = 0; i < n; i += l << 1)
			for(int j = 0; j < l; j++)
			{
				comp_t x = a[i + j], y = a[i + j + l] * w[j];
				a[i + j] = x + y, a[i + j + l] = x - y;
			}
	}
	if(f == -1)
		for(int i = 0; i < n; i++)
			a[i].x /= n;
}

int main()
{
	int n, m, L, k;
	gi(n), gi(m);
	++n, ++m;
	for(int i = 0; i < n; i++)
		gi(F[i].x);
	for(int i = 0; i < m; i++)
		gi(F[i].y);
	for(L = 1, k = -1; L < n + m; L <<= 1, ++k);
	for(int i = 1; i < L; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << k);
	dft(F, L, 1);
	for(int i = 0; i < L; i++)
	{
		int j = (L - i) & (L - 1);
		A[i] = ((F[i] + F[j].conj()) * comp_t(0.5, 0)) * ((F[i] - F[j].conj()) * comp_t(0, -0.5));
	}
	dft(A, L, -1);
	for(int i = 0; i < n + m - 1; i++)
		print((int) (A[i].x + 0.5)), pc(' ');
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #12.694 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #224.686 ms27 MB + 164 KBAcceptedScore: 100

Subtask #1 Testcase #311.947 ms24 MB + 184 KBAcceptedScore: 0

Subtask #1 Testcase #411.941 ms24 MB + 160 KBAcceptedScore: 0

Subtask #1 Testcase #52.578 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #62.691 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #72.574 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #823.937 ms26 MB + 584 KBAcceptedScore: 0

Subtask #1 Testcase #923.867 ms26 MB + 584 KBAcceptedScore: 0

Subtask #1 Testcase #1022.919 ms25 MB + 1004 KBAcceptedScore: 0

Subtask #1 Testcase #1124.884 ms27 MB + 324 KBAcceptedScore: 0

Subtask #1 Testcase #1220.927 ms25 MB + 84 KBAcceptedScore: 0

Subtask #1 Testcase #132.661 ms22 MB + 960 KBAcceptedScore: 0


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