提交记录 17720


用户 题目 状态 得分 用时 内存 语言 代码长度
1443356159 1002i. 【模板题】多项式乘法 Accepted 100 52.02 ms 7712 KB C++ 1.54 KB
提交时间 评测时间
2022-05-28 15:47:30 2022-05-28 15:47:34
#include<bits/stdc++.h>
using namespace std;
typedef long long lxl;
const int MOD=998244353,G=3;
const int base=18;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch))(ch=='-')&&(f=-f),ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}
inline int expow(int n,int k){
	int ans=1;
	for(;k;k>>=1,n=1ll*n*n%MOD)(k&1)&&(ans=1ll*ans*n%MOD);
	return ans;
}

int w[1<<base];
inline void init(){
	for(int len=1;len<(1<<base);len<<=1){
		const int tmp=expow(G,MOD/(len<<1));w[len]=1;
		for(int i=1;i<len;++i) w[i|len]=1ll*w[(i-1)|len]*tmp%MOD;
	}
}

int tr[1<<base];
inline void gettr(int n){
	for(int i=0;i<n;++i)
		tr[i]=(tr[i>>1]>>1)|((i&1)?n>>1:0); 
}
inline void NTT(int *a,int n,bool type){
	int i,j,len;
	static lxl T[1<<base];
	for(i=0;i<n;++i) T[tr[i]]=a[i];
	for(len=1;len<n;len<<=1){
		if(len==(1<<16)) for(i=0;i<n;++i) T[i]%=MOD;
		for(i=0;i<n;i+=(len<<1))
			for(j=0;j<len;++j){
				const int tmp=1ull*T[i|j|len]*w[j|len]%MOD;
				T[i|j|len]=T[i|j]+MOD-tmp;T[i|j]+=tmp;
			}
	}
	for(i=0;i<n;++i) a[i]=T[i]%MOD;
	if(type) return;reverse(a+1,a+n);
	const int inv=expow(n,MOD-2);
	for(i=0;i<n;++i) a[i]=1ll*a[i]*inv%MOD;
}
inline void cdot(int *a,int *b,int n,int *c){
	for(int i=0;i<n;++i) c[i]=1ll*a[i]*b[i]%MOD;
}

int n,f[1<<base];
int m,g[1<<base];

int main(){
	int i,lim;init();
	n=read()+1;m=read()+1;
	for(i=0;i<n;++i) f[i]=read();
	for(i=0;i<m;++i) g[i]=read();
	for(lim=1;lim<(n+m-1);lim<<=1);
	gettr(lim);NTT(f,lim,1);NTT(g,lim,1);
	cdot(f,g,lim,f);NTT(f,lim,0);
	for(i=0;i<n+m-1;++i) printf("%d ",f[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.1 ms1 MB + 52 KBAcceptedScore: 0

Subtask #1 Testcase #251.145 ms7 MB + 464 KBAcceptedScore: 0

Subtask #1 Testcase #323.195 ms3 MB + 844 KBAcceptedScore: 100

Subtask #1 Testcase #423.248 ms3 MB + 832 KBAcceptedScore: 0

Subtask #1 Testcase #51.102 ms1 MB + 52 KBAcceptedScore: 0

Subtask #1 Testcase #61.101 ms1 MB + 52 KBAcceptedScore: 0

Subtask #1 Testcase #71.101 ms1 MB + 52 KBAcceptedScore: 0

Subtask #1 Testcase #846.025 ms7 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #946.078 ms7 MB + 196 KBAcceptedScore: 0

Subtask #1 Testcase #1040.927 ms6 MB + 952 KBAcceptedScore: 0

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

Subtask #1 Testcase #1252.02 ms6 MB + 424 KBAcceptedScore: 0

Subtask #1 Testcase #131.1 ms1 MB + 52 KBAcceptedScore: 0


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