提交记录 13363


用户 题目 状态 得分 用时 内存 语言 代码长度
hs_black 1002i. 【模板题】多项式乘法 Accepted 100 29.957 ms 96344 KB C++ 2.85 KB
提交时间 评测时间
2020-08-01 11:41:22 2020-08-01 11:41:26
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

int read(void) {
    int x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x; return x;
}

inline void write(int x, char ed = '\n')
{
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

#define op com operator 
#define con const
typedef double db;
const int N = 3000005;
const double Pi = acos(-1.0);
struct com {
	db x, y;
	com(db a = 0, db b = 0) : x(a) , y(b) {}
	op + (con com &w) con { return com(x + w.x, y + w.y); }
	op - (con com &w) con { return com(x - w.x, y - w.y); }
	op * (con com &w) con { return com(x * w.x - y * w.y, x * w.y + y * w.x); }
	op - (void) con { return com(-x, -y); }
	com mi() con { return com(-y, x); }
}A[N], E[N];

int r[N], lim = 1, L; 
void dft(com *A) {
	for (int i = 1;i < lim; i++)
		if (r[i] > i) swap(A[i], A[r[i]]);
	if (lim >= 2) 
	for (int j = 0;j < lim; j += 2) {
		com x = A[j], y = A[j+1];
		A[j] = x + y, A[j+1] = x - y;
	}
	if (lim >= 4)
	for (int j = 0;j < lim; j += 4) {
		com x = A[j], y = A[j+2];
		A[j] = x + y, A[j+2] = x - y;
		x = A[j+1], y = A[j+3].mi();
		A[j+1] = x + y, A[j+3] = x - y;
	}
	if (lim >= 8)
	for (int j = 0;j < lim; j += 8) {
		com x = A[j], y = A[j+4];
		A[j] = x + y, A[j+4] = x - y;
		x = A[j+1], y = A[j+5] * E[5];
		A[j+1] = x + y, A[j+5] = x - y;
		x = A[j+2], y = A[j+6].mi();
		A[j+2] = x + y, A[j+6] = x - y;
		x = A[j+3], y = A[j+7] * E[7];
		A[j+3] = x + y, A[j+7] = x - y;
	}
	for (int i = 8;i < lim; i <<= 1) {
		for (int j = 0;j < lim; j += (i << 1)) {
			com *f = A + j, *g = f + i, *e = E + i;
			for (int k = 0;k < i; k++) {
				com x = f[k], y = g[k] * e[k];
				f[k] = x + y, g[k] = x - y;
				k++;
				x = f[k], y = g[k] * e[k];
				f[k] = x + y, g[k] = x - y;
			}
		}
	}
}

int m, n;
int main() {
	n = read(), m = read();
	for (int i = 0;i <= n; i++) A[i].x = read();
	for (int i = 0;i <= m; i++) A[i].y = read();
	while (lim <= (n + m)) lim <<= 1, L++;
	int len = lim >> 1;
	for (int i = 1;i < lim; i++)
		r[i] = r[i >> 1] >> 1 | ((i & 1) ? len : 0);
	E[1] = com(1, 0);
	for (int i = 2;i < lim; i <<= 1) {
		com *e0 = E + i / 2, *e1 = E + i;
		com w(cos(Pi / i), sin(Pi / i));
		for (int j = 0;j < i; j += 2) 
			e1[j] = e0[j>>1], e1[j+1] = e1[j] * w;
	}
	dft(A);
	for (int i = 0;i < lim; i++) A[i] = A[i] * A[i];
	dft(A); reverse(A + 1, A + lim); lim *= 2;
	for (int i = 0;i <= n + m; i++)
		write((int)(A[i].y / lim + 0.5), ' ');
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110.42 ms91 MB + 604 KBAcceptedScore: 0

Subtask #1 Testcase #229.957 ms94 MB + 8 KBAcceptedScore: 0

Subtask #1 Testcase #317.993 ms92 MB + 372 KBAcceptedScore: 100

Subtask #1 Testcase #418.345 ms92 MB + 360 KBAcceptedScore: 0

Subtask #1 Testcase #510.361 ms91 MB + 604 KBAcceptedScore: 0

Subtask #1 Testcase #610.531 ms91 MB + 604 KBAcceptedScore: 0

Subtask #1 Testcase #710.547 ms91 MB + 604 KBAcceptedScore: 0

Subtask #1 Testcase #828.473 ms93 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #928.895 ms93 MB + 764 KBAcceptedScore: 0

Subtask #1 Testcase #1027.391 ms93 MB + 496 KBAcceptedScore: 0

Subtask #1 Testcase #1129.703 ms94 MB + 88 KBAcceptedScore: 0

Subtask #1 Testcase #1225.828 ms92 MB + 992 KBAcceptedScore: 0

Subtask #1 Testcase #1310.355 ms91 MB + 604 KBAcceptedScore: 0


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