提交记录 15239


用户 题目 状态 得分 用时 内存 语言 代码长度
asd_a 1002i. 【模板题】多项式乘法 Accepted 100 71.894 ms 6472 KB C++ 1.38 KB
提交时间 评测时间
2020-12-14 19:26:58 2020-12-14 19:27:01
#include<bits/stdc++.h>
using namespace std;
const int N=4e6+5;
const int p=998244353;
const int gen=3;
inline bool isnum(char &ch){return ch>='0'&&ch<='9';}
inline int rd(){
	int x=0,fl=1;char ch;
	while(!isnum(ch=getchar()))fl=ch=='-'?-1:1;
	for(x=ch^48;isnum(ch=getchar());x=(x<<1)+(x<<3)+(ch^48));
	return x*fl;
}
inline int fp(int x,int y){
	int ans=1;
	for(;y;y>>=1){
		if(y&1)ans=(1ll*ans*x)%p;
		x=(1ll*x*x)%p;
	}
	return ans;
}
namespace NTT{
	int rev[N],A[N],B[N];
	inline void ntt(int *a,int lim,int fl=1){
		for(int i=0;i<lim;i++){
			rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
			if(i<rev[i])swap(a[i],a[rev[i]]);
		}
		for(int k=1;k<lim;k<<=1){
			int o=fp(gen,(p-1)/(k<<1));if(!fl)o=fp(o,p-2);
			for(int j=0;j<lim;j+=k<<1)
				for(int i=j,w=1;i<j+k;i++,w=(1ll*w*o)%p){
					int t=(1ll*w*a[i+k])%p;
					a[i+k]=(a[i]+p-t)%p;
					a[i]=(a[i]+t)%p;
				}
		}
		if(!fl)for(int i=0,iv=fp(lim,p-2);i<lim;i++)a[i]=(1ll*a[i]*iv)%p;
	}
	inline void mul(int *a,int *b,int n,int m,int *c){
		int lim=1;while(lim<n+m)lim<<=1;
		for(int i=0;i<n;i++)A[i]=a[i];for(int i=0;i<m;i++)B[i]=b[i];
		ntt(A,lim);ntt(B,lim);for(int i=0;i<lim;i++)c[i]=(1ll*A[i]*B[i])%p;
		ntt(c,lim,0);for(int i=0;i<lim;i++)A[i]=B[i]=0;
	}
}
int n,m,f[N],g[N],h[N];
int main(){
	n=rd();m=rd();
	for(int i=0;i<=n;i++)f[i]=rd();
	for(int i=0;i<=m;i++)g[i]=rd();
	NTT::mul(f,g,n+1,m+1,h);
	for(int i=0;i<=n+m;i++)printf("%d ",h[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #137.22 us60 KBAcceptedScore: 0

Subtask #1 Testcase #270.961 ms6 MB + 248 KBAcceptedScore: 0

Subtask #1 Testcase #332.8 ms2 MB + 732 KBAcceptedScore: 100

Subtask #1 Testcase #432.878 ms2 MB + 720 KBAcceptedScore: 0

Subtask #1 Testcase #540.48 us60 KBAcceptedScore: 0

Subtask #1 Testcase #639.25 us60 KBAcceptedScore: 0

Subtask #1 Testcase #738.32 us60 KBAcceptedScore: 0

Subtask #1 Testcase #865.886 ms5 MB + 868 KBAcceptedScore: 0

Subtask #1 Testcase #966.022 ms5 MB + 868 KBAcceptedScore: 0

Subtask #1 Testcase #1060.782 ms5 MB + 464 KBAcceptedScore: 0

Subtask #1 Testcase #1171.573 ms6 MB + 328 KBAcceptedScore: 0

Subtask #1 Testcase #1271.894 ms5 MB + 208 KBAcceptedScore: 0

Subtask #1 Testcase #1337.89 us60 KBAcceptedScore: 0


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