提交记录 16019


用户 题目 状态 得分 用时 内存 语言 代码长度
leukocyte 1002i. 【模板题】多项式乘法 Accepted 100 51.45 ms 10132 KB C++11 1.90 KB
提交时间 评测时间
2021-03-16 11:09:20 2021-03-16 11:09:24
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=1e5,maxf=1<<18;
const int mod=998244353;
namespace usual{
	int add(int ta,int tb){ return ta+tb>=mod?ta+tb-mod:ta+tb; }
	int sub(int ta,int tb){ return ta<tb?ta-tb+mod:ta-tb; }
	int ksm(ll ta,int tp){
		int s=1;
		for(;tp;ta=ta*ta%mod,tp>>=1) if(tp&1) s=ta*s%mod;
		return s;
	}
}
using namespace usual;
namespace poly{
	int pa[maxf+5],pb[maxf+5];
	int rev[maxf+5],g[maxf+5],invg[maxf+5];
	void Cpy(int *A,int *B,int len){
		for(int i=0;i<len;i++) A[i]=B[i];
	}
	void Cl(int *A,int len){
		memset(A,0,len*4);
	}
	void make_tt(int *T,int len,int da){
		int tmp=ksm(da,(mod-1)/len); T[len>>1]=1;
		for(int i=(len>>1)+1;i<len;i++) T[i]=(0ll+T[i-1])*tmp%mod;
		for(int i=(len>>1)-1;i;i--) T[i]=T[i<<1];
	}
	void pre_poly(int len){
		make_tt(g,len,3); make_tt(invg,len,332748118);
	}
	void make_rev(int len){
		for(int i=1;i<len;i++) rev[i]=(rev[i>>1]>>1)|(i&1?len>>1:0);
	}
	void NTT(int *T,int len,bool ok){
		static unsigned long long s[maxf+5];
		int *tt=ok?g:invg,ny;
		for(int i=0;i<len;i++) s[rev[i]]=T[i];
		for(int i=1;i<len;i<<=1)
			for(int j=0;j<len;j+=i<<1)
				for(int l=0;l<i;l++){
					ny=s[i+j+l]*tt[i+l]%mod;
					s[i+j+l]=s[j+l]+mod-ny; s[j+l]+=ny;
				}
		for(int i=0;i<len;i++) T[i]=s[i]%mod;
	}
	void Mult(int *A,int *B,int *C,int len){
		Cpy(pa,A,len); Cpy(pb,B,len);
		make_rev(len);
		NTT(pa,len,1); NTT(pb,len,1);
		for(int i=0;i<len;i++) pa[i]=(0ll+pa[i])*pb[i]%mod;
		NTT(pa,len,0);
		int invn=ksm(len,mod-2);
		for(int i=0;i<len;i++) C[i]=(0ll+pa[i])*invn%mod;
	}
}
using namespace poly;
int n,m;
int F[maxf+5],G[maxf+5];
int main(){
	int len=1;
	scanf("%d %d",&n,&m); n++; m++;
	while(len<n+m) len<<=1;
	for(int i=0;i<n;i++) scanf("%d",&F[i]);
	for(int i=0;i<m;i++) scanf("%d",&G[i]);
	pre_poly(len);
	Mult(F,G,F,len);
	for(int i=0;i<n+m-1;i++)
		printf("%d ",F[i]);
	printf("\n");
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #111.72 us48 KBAcceptedScore: 0

Subtask #1 Testcase #251.33 ms9 MB + 836 KBAcceptedScore: 100

Subtask #1 Testcase #322.685 ms4 MB + 716 KBAcceptedScore: 0

Subtask #1 Testcase #422.739 ms4 MB + 316 KBAcceptedScore: 0

Subtask #1 Testcase #512.88 us48 KBAcceptedScore: 0

Subtask #1 Testcase #611.96 us48 KBAcceptedScore: 0

Subtask #1 Testcase #712.35 us48 KBAcceptedScore: 0

Subtask #1 Testcase #845.522 ms9 MB + 568 KBAcceptedScore: 0

Subtask #1 Testcase #945.448 ms9 MB + 436 KBAcceptedScore: 0

Subtask #1 Testcase #1039.756 ms9 MB + 168 KBAcceptedScore: 0

Subtask #1 Testcase #1151.45 ms9 MB + 916 KBAcceptedScore: 0

Subtask #1 Testcase #1251.242 ms8 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #1311.62 us48 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:41:49 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠