提交记录 15208


用户 题目 状态 得分 用时 内存 语言 代码长度
Wallbreaker5th 1002i. 【模板题】多项式乘法 Accepted 100 72.385 ms 8128 KB C++ 1.55 KB
提交时间 评测时间
2020-12-14 11:16:17 2020-12-14 11:16:21
//review ntt
#include<bits/stdc++.h>
using namespace std;
const int LEN=1<<19;
#define uint unsigned int
inline char gc(){
	static char buf[LEN+10],*PT=buf,*PTEND=buf+LEN;
	return ((PT==PTEND)&&(fread(buf,1,LEN,stdin),PT=buf)),*(PT++);
}
inline uint getint(){
	uint ans=0;
	char c=gc();
	while(c<'0'||c>'9')c=gc();
	while(c>='0'&&c<='9'){
		ans=ans*10+c-'0';
		c=gc();
	}
	return ans;
}
const int N=4e5+10,mod=998244353,G=3;

int w[N],iw[N];
int a[N],b[N],c[N];
int rev[N];

int qpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=ans*1ll*x%mod;
		x=x*1ll*x%mod;
		y>>=1;
	}
	return ans;
}
void ntt(int *a,int n,int r=1){
	int *W=(~r?w:iw);
	for(int i=0;i<n;i++)
		if(i>rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<n;i<<=1){
		int d=n/i/2;
		for(int j=0;j<n;j+=i<<1){
			int t=0;
			for(int k=0;k<i;k++,t+=d){
				int x=a[j+k],y=W[t]*1ll*a[j+k+i]%mod;
				a[j+k]=(x+y)%mod;
				a[j+k+i]=(x-y+mod)%mod;
			}
		}
	}
	if(r==-1){
		int invn=qpow(n,mod-2);
		for(int i=0;i<n;i++){
			a[i]=a[i]*1ll*invn%mod;
		}
	}
}
void init_w(int n){
	w[0]=iw[0]=1;
	w[1]=qpow(G,(mod-1)/n);
	iw[1]=qpow(w[1],mod-2);
	for(int i=2;i<n;i++)
		w[i]=w[i>>1]*1ll*w[i>>1]%mod*w[i&1]%mod,
		iw[i]=iw[i>>1]*1ll*iw[i>>1]%mod*iw[i&1]%mod;
}

int main(){
	int n=getint(),m=getint();
	int nm=1,l=0;
	while(nm<=n+m)nm<<=1,l++;
	for(int i=1;i<nm;i++)
		rev[i]=rev[i>>1]>>1|((i&1)<<(l-1));
	init_w(nm);
	for(int i=0;i<=n;i++)a[i]=getint();
	for(int i=0;i<=m;i++)b[i]=getint();
	ntt(a,nm);
	ntt(b,nm);
	for(int i=0;i<nm;i++)c[i]=a[i]*1ll*b[i]%mod;
	ntt(c,nm,-1);
	for(int i=0;i<=m+n;i++)printf("%d ",c[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #1325.35 us64 KBAcceptedScore: 0

Subtask #1 Testcase #272.038 ms7 MB + 880 KBAcceptedScore: 0

Subtask #1 Testcase #328.937 ms3 MB + 536 KBAcceptedScore: 100

Subtask #1 Testcase #428.967 ms3 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #5326.66 us64 KBAcceptedScore: 0

Subtask #1 Testcase #6326.1 us64 KBAcceptedScore: 0

Subtask #1 Testcase #7325.12 us64 KBAcceptedScore: 0

Subtask #1 Testcase #866.898 ms7 MB + 544 KBAcceptedScore: 0

Subtask #1 Testcase #966.793 ms7 MB + 544 KBAcceptedScore: 0

Subtask #1 Testcase #1061.843 ms7 MB + 212 KBAcceptedScore: 0

Subtask #1 Testcase #1172.385 ms7 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #1272.096 ms6 MB + 840 KBAcceptedScore: 0

Subtask #1 Testcase #13324.95 us64 KBAcceptedScore: 0


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