提交记录 28704


用户 题目 状态 得分 用时 内存 语言 代码长度
wxqwq 1002i. 【模板题】多项式乘法 Accepted 100 71.716 ms 14896 KB C++17 1.37 KB
提交时间 评测时间
2025-11-25 17:50:17 2025-11-25 17:50:22
#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0' || ch>'9') {if(ch=='-') f=1;ch=getchar();}
	while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}

#define x first
#define y second

typedef pair<int,int> PII;
typedef long long LL;
const int N=3e6+10;
const double PI=acos(-1);

int A,B;
int n,bit;
int rev[N];
struct Complex{
	double x,y;
	Complex operator+(Complex b){return {x+b.x,y+b.y};}
	Complex operator-(Complex b){return {x-b.x,y-b.y};}
	Complex operator*(Complex b){return {x*b.x-y*b.y,x*b.y+y*b.x};}
}a[N],b[N],w[N];

void fft(Complex a[],int inv)
{
	for(int i=0;i<n;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
	if(inv==-1) for(int i=0;i<n;i++) w[i].y=-w[i].y;
	for(int d=1,t=n>>1;d<n;d<<=1,t>>=1)
		for(int i=0;i<n;i+=(d<<1))
			for(int j=0;j<d;j++){
				auto tmp=a[i+j+d]*w[t*j];
				a[i+j+d]=a[i+j]-tmp,a[i+j]=a[i+j]+tmp;
			}
	if(inv==-1) for(int i=0;i<n;i++) w[i].y=-w[i].y;
}

int main()
{
	A=read(),B=read();
	for(int i=0;i<=A;i++) a[i].x=read();
	for(int i=0;i<=B;i++) b[i].x=read();
	
	while((1<<bit)<=A+B) bit++; n=1<<bit;
	for(int i=0;i<n;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
	for(int i=0;i<n;i++) w[i]={cos(2*PI/n*i),sin(2*PI/n*i)};
	
	fft(a,1),fft(b,1);
	for(int i=0;i<n;i++) a[i]=a[i]*b[i];
	fft(a,-1);
	for(int i=0;i<=A+B;i++) printf("%d ",(int)(a[i].x/n+0.5));
	
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #143.6 us52 KBAcceptedScore: 100

Subtask #1 Testcase #270.502 ms14 MB + 480 KBAcceptedScore: 0

Subtask #1 Testcase #330.86 ms6 MB + 844 KBAcceptedScore: 0

Subtask #1 Testcase #430.872 ms6 MB + 832 KBAcceptedScore: 0

Subtask #1 Testcase #538.63 us52 KBAcceptedScore: 0

Subtask #1 Testcase #637.31 us52 KBAcceptedScore: 0

Subtask #1 Testcase #737.18 us52 KBAcceptedScore: 0

Subtask #1 Testcase #865.309 ms14 MB + 212 KBAcceptedScore: 0

Subtask #1 Testcase #965.151 ms14 MB + 212 KBAcceptedScore: 0

Subtask #1 Testcase #1059.889 ms13 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #1170.907 ms14 MB + 560 KBAcceptedScore: 0

Subtask #1 Testcase #1271.716 ms13 MB + 440 KBAcceptedScore: 0

Subtask #1 Testcase #1336.45 us52 KBAcceptedScore: 0


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