提交记录 8544


用户 题目 状态 得分 用时 内存 语言 代码长度
OI_berbi 1002i. 【模板题】多项式乘法 Accepted 100 76.866 ms 15676 KB C++ 1.34 KB
提交时间 评测时间
2019-02-24 19:39:03 2020-08-01 01:20:51
#include <bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
using namespace std;
namespace FFT {
	const int N=270000;
	const double pi=acos(-1);
	struct cp {
		double x,y;
		cp operator + (const cp &_) {return (cp){x+_.x,y+_.y};}
		cp operator - (const cp &_) {return (cp){x-_.x,y-_.y};}
		cp operator * (const cp &_) {return (cp){x*_.x-y*_.y,x*_.y+y*_.x};}
	}A[N],B[N],W[N],y;
	int R[N];
	void DFT (cp *A,int n,int o) {
		For(i,0,n-1) if (i<R[i]) swap(A[i],A[R[i]]);
		for(int i=2;i<=n;i<<=1) {
			for(int j=0;j<n;j+=i) {
				For(k,0,(i>>1)-1) {
					y=W[n/i*k]*A[j+k+(i>>1)];
					A[j+k+(i>>1)]=A[j+k]-y;
					A[j+k]=A[j+k]+y;
				}
			}
		}
		if (o<0) For(i,0,n-1) A[i].x/=n;
	}
	void Mul (int *_A,int a,int *_B,int b) {
		int n=(1<<(int)log2(a+b)<<1);
		For(i,0,n-1) R[i]=(R[i>>1]>>1)|((i&1)*(n>>1));
		For(i,0,a-1) A[i].x=_A[i];
		For(i,0,b-1) B[i].x=_B[i];
		cp t=(cp){cos(2*pi/n),sin(2*pi/n)};
		W[0]=(cp){1,0}; For(i,1,n-1) W[i]=W[i-1]*t;
		DFT(A,n,1),DFT(B,n,1);
		t=(cp){cos(2*pi/n),-sin(2*pi/n)};
		W[0]=(cp){1,0}; For(i,1,n-1) W[i]=W[i-1]*t;
		For(i,0,n-1) A[i]=A[i]*B[i];
		DFT(A,n,-1);
		For(i,0,n-1) _A[i]=A[i].x+0.5;
	}
}
using FFT::Mul;

const int N=100007;
int A[N],B[N],a,b;
int main () {
	scanf("%d%d",&a,&b),++a,++b;
	For(i,0,a-1) scanf("%d",&A[i]);
	For(i,0,b-1) scanf("%d",&B[i]);
	Mul(A,a,B,b);
	For(i,0,a+b-2) printf("%d ",A[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #139.69 us60 KBAcceptedScore: 0

Subtask #1 Testcase #276.054 ms15 MB + 236 KBAcceptedScore: 100

Subtask #1 Testcase #333.137 ms7 MB + 600 KBAcceptedScore: 0

Subtask #1 Testcase #433.152 ms7 MB + 204 KBAcceptedScore: 0

Subtask #1 Testcase #541.72 us60 KBAcceptedScore: 0

Subtask #1 Testcase #638.93 us60 KBAcceptedScore: 0

Subtask #1 Testcase #739.52 us60 KBAcceptedScore: 0

Subtask #1 Testcase #870.361 ms14 MB + 992 KBAcceptedScore: 0

Subtask #1 Testcase #970.507 ms14 MB + 864 KBAcceptedScore: 0

Subtask #1 Testcase #1064.531 ms14 MB + 596 KBAcceptedScore: 0

Subtask #1 Testcase #1176.866 ms15 MB + 316 KBAcceptedScore: 0

Subtask #1 Testcase #1275.404 ms14 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #1338.03 us60 KBAcceptedScore: 0


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