提交记录 12667


用户 题目 状态 得分 用时 内存 语言 代码长度
darken 1002i. 【模板题】多项式乘法 Accepted 100 86.482 ms 58196 KB C++ 1.68 KB
提交时间 评测时间
2020-04-27 16:49:06 2020-08-01 02:57:23
// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
double pi(acos(-1));
struct comp {
	double s,x;
	inline comp operator+(const comp&b) const {
		return(comp) {
			s+b.s,x+b.x
		};
	}
	inline comp operator-(const comp&b) const {
		return(comp) {
			s-b.s,x-b.x
		};
	}
	inline comp operator*(const comp&b) const {
		return(comp) {
			s*b.s-x*b.x,s*b.x+b.s*x
		};
	}
	comp (double xx=0,double yy=0) {
		s=xx,x=yy;
	}
} a[3100010];
int n,m;
void DFT(comp a[],int len) {
	if(len<=1)return;
	comp A0[(len>>1)+1],A1[(len>>1)+1];
	for(int i=0; i<=len; i+=2)
		A0[i>>1]=a[i],A1[i>>1]=a[i+1];
	DFT(A0,len>>1);
	DFT(A1,len>>1);
	comp w=(comp) {
		cos(2.0*pi/len),sin(2.0*pi/len)
	};
	comp d=(comp) {
		1.0,0.0
	};
	for(int i=0; i<len/2; i++,d=d*w) {
		a[i]=A0[i]+A1[i]*d;
		a[i+(len>>1)]=A0[i]-A1[i]*d;
	}
	return;
}
void IDFT(comp a[],int len) {
	if(len<=1)return;
	comp A0[(len>>1)+1],A1[(len>>1)+1];
	for(int i=0; i<=len; i+=2)
		A0[i>>1]=a[i],A1[i>>1]=a[i+1] ;
	IDFT(A0,len>>1);
	IDFT(A1,len>>1);
	comp w=(comp) {
		cos(2.0*pi/len),sin(2.0*pi/len)*(-1.0)
	};
	comp d=(comp) {
		1.0,0.0
	};
	for(int i=0; i<len/2; i++,d=d*w) {
		a[i]=A0[i]+A1[i]*d;
		a[i+(len>>1)]=A0[i]-A1[i]*d;
	}
	return;
}
long long int p;
int main() {
	scanf("%d%d",&n,&m);
	for(int i=0; i<=n; i++) {
		int x(0);
		scanf("%d",&x);
		a[i].s=(double)x;
	}
	for(int i=0; i<=m; i++) {
		int x(0);
		scanf("%d",&x);
		a[i].x=(double)x;
	}
	int lenth(1);
	while(lenth<=n+m+2)lenth=lenth<<1;
	DFT(a,lenth);
	for(int i=0; i<lenth; i++) {
		a[i]=a[i]*a[i];
	}
	IDFT(a,lenth);
	for(int i=0; i<lenth; i++)
		a[i].x/=(double)lenth;
	for(int i=0; i<=n+m; i++) {
		printf("%lld ",(long long)(a[i].x/2.0+0.1));
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #15.357 ms47 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #285.714 ms56 MB + 772 KBAcceptedScore: 0

Subtask #1 Testcase #342.413 ms51 MB + 624 KBAcceptedScore: 100

Subtask #1 Testcase #442.484 ms51 MB + 612 KBAcceptedScore: 0

Subtask #1 Testcase #55.312 ms47 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #65.57 ms47 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #75.314 ms47 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #879.486 ms56 MB + 504 KBAcceptedScore: 0

Subtask #1 Testcase #979.668 ms56 MB + 504 KBAcceptedScore: 0

Subtask #1 Testcase #1073.514 ms56 MB + 236 KBAcceptedScore: 0

Subtask #1 Testcase #1186.052 ms56 MB + 852 KBAcceptedScore: 0

Subtask #1 Testcase #1286.482 ms55 MB + 732 KBAcceptedScore: 0

Subtask #1 Testcase #135.318 ms47 MB + 344 KBAcceptedScore: 0


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