提交记录 5188


用户 题目 状态 得分 用时 内存 语言 代码长度
HowNegative 1002i. 【模板题】多项式乘法 Accepted 100 33.249 ms 17824 KB C++ 2.42 KB
提交时间 评测时间
2018-08-10 14:46:29 2020-08-01 00:13:41
#include<cstdio>
#include<algorithm>
#include<ctype.h>
#include<string.h>
#include<math.h>

using namespace std;
#define ll long long
#define travel(i,x) for(int i=h[x];i;i=pre[i])

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^ '0');
	if (iosig) x = -x;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
	if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
	*ooh++ = c;
}
template<class T>
inline void print(T x) {
	static int buf[30], cnt;
	if (x == 0) print('0');
	else {
		if (x < 0) print('-'), x = -x;
		for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
		while (cnt) print((char)buf[cnt--]);
	}
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
const double pi = acos(-1);
const int N = 1<<18;
int n, m, p;
struct cp{
	double a, b;
	inline cp operator +(const cp &rhs)const{ return (cp){a+rhs.a, b+rhs.b};}
	inline cp operator -(const cp &rhs)const{ return (cp){a-rhs.a, b-rhs.b};}
	inline cp operator *(const cp &rhs)const{ return (cp){a*rhs.a-b*rhs.b, a*rhs.b+b*rhs.a};}
	inline cp operator *(const double rhs)const{ return (cp){a*rhs, b*rhs};}
}a[N], b[N], w[N], wp[N|1];
inline void FFT(cp *f, int g){
	for(register int i=0, j=0; i<p; ++i){
		if(i>j) swap(f[i], f[j]);
		for(register int k=p>>1; (j^=k)<k; k>>=1);
	}
	for(register int i=1; i<p; i<<=1){
		if(g==1) for(int j=0, k=0; j<i; ++j, k+=p/i/2) w[j]=wp[k]; else for(int j=0, k=p; j<i; ++j, k-=p/i/2) w[j]=wp[k];
		for(register int j=0; j<p; j+=i<<1){
			for(register int k=j; k<j+i; ++k){
				cp t=f[k+i]*w[k-j];
				f[k+i]=f[k]-t;
				f[k]=f[k]+t;
			}
		}
	}
}
int main() {
	read(n), read(m), ++n, ++m;
	for(int i=0; i<n; ++i){register int tmp; read(tmp); a[i].a=tmp;}
	for(int i=0; i<m; ++i){register int tmp; read(tmp); b[i].a=tmp;}
	for(p=1; p<n+m-1; p<<=1);
	wp[0]=(cp){1, 0};
	cp w0=(cp){cos(2*pi/p), sin(2*pi/p)};
	for(int i=1; i<=p; ++i) wp[i]=wp[i-1]*w0;
	FFT(a, 1), FFT(b, 1);
	for(int i=0; i<p; ++i) a[i]=a[i]*b[i];
	FFT(a, -1);
	for(int i=0; i<n+m-1; ++i) print((int)(a[i].a/p+0.5)), print(' ');
	return flush(), 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #18.53 us40 KBAcceptedScore: 0

Subtask #1 Testcase #232.953 ms17 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #313.106 ms7 MB + 796 KBAcceptedScore: 100

Subtask #1 Testcase #413.181 ms7 MB + 776 KBAcceptedScore: 0

Subtask #1 Testcase #58.82 us40 KBAcceptedScore: 0

Subtask #1 Testcase #68.75 us40 KBAcceptedScore: 0

Subtask #1 Testcase #78.53 us40 KBAcceptedScore: 0

Subtask #1 Testcase #832.133 ms16 MB + 672 KBAcceptedScore: 0

Subtask #1 Testcase #932.095 ms16 MB + 672 KBAcceptedScore: 0

Subtask #1 Testcase #1031.195 ms16 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #1133.249 ms17 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #1229.513 ms15 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #137.59 us36 KBAcceptedScore: 0


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