提交记录 11376


用户 题目 状态 得分 用时 内存 语言 代码长度
supy 1002i. 【模板题】多项式乘法 Accepted 100 55.272 ms 4928 KB C++ 1.64 KB
提交时间 评测时间
2019-12-17 22:08:10 2020-08-01 02:42:50
#include<cstdio>
#include<cstring>
#include<iostream>
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; --i)
using namespace std;
const int N = 280000, mo = 998244353;
int n,m,a[N],b[N],c[N],w[N];
inline void read(int &x) {
	x=0; char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}
inline int power(int a, int n) {
	int res=1;
	while (n) {
		if (n&1) res=1LL*res*a%mo;
		a=1LL*a*a%mo; n>>=1;
	}
	return res;
}
inline void exgcd(int a, int b, int &x, int &y) {
	if (!b) {x=1; y=0; return;}
	exgcd(b,a%b,y,x); y-=a/b*x;
}
inline int inv(int a) {int x,y; exgcd(a,mo,x,y); return x>=0 ? x : x+mo;}
inline void getmod(int &x){x+=x>>31&mo;}
inline void fft(int *a, int n, int tp) {
	for (int i=1,j=0; i<n; i++) {
		for (int k=n>>1; !((j^=k)&k); k>>=1);
		if (i<j) swap(a[i],a[j]);
	}
	for (int j=2; j<=n; j<<=1) {
		w[0]=1; w[1]=power(3,(mo-1)/j); w[1]=tp==1?w[1]:inv(w[1]); int m=(j>>1)-1; //mo-1
		rep(i,2,m) w[i]=1LL*w[i-1]*w[1]%mo;
		for (register int i=0; i<n; i+=j) rep(k,0,m) {
			int x=1LL*a[i+k+(j>>1)]*w[k]%mo;
			getmod(a[i+k+(j>>1)]=a[i+k]-x);
			getmod(a[i+k]=a[i+k]+x-mo);
		}
	}
}
inline void mul(int *a, int *b, int l1, int l2, int *c){//a[0..l1]*b[0..l2]-->c[0..l1+l2]
	int n;for(n=1;n<=l1+l2;n<<=1);
	rep(i,l1+1,n-1)a[i]=0;rep(i,l2+1,n-1)b[i]=0;
	fft(a,n,1);fft(b,n,1);rep(i,0,n-1)a[i]=1LL*a[i]*b[i]%mo;
	fft(a,n,-1);int ni=inv(n);rep(i,0,l1+l2)c[i]=1LL*a[i]*ni%mo;
}
int main() {
//	freopen("1.in","r",stdin);
	read(n); read(m);
	rep(i,0,n) read(a[i]);
	rep(i,0,m) read(b[i]);
	mul(a,b,n,m,c);int len=n+m;
	for (int i=0;i<=len;i++) printf("%d ",c[i]);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #137.69 us52 KBAcceptedScore: 0

Subtask #1 Testcase #254.99 ms4 MB + 752 KBAcceptedScore: 100

Subtask #1 Testcase #325.096 ms1 MB + 980 KBAcceptedScore: 0

Subtask #1 Testcase #425.255 ms1 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #539.48 us52 KBAcceptedScore: 0

Subtask #1 Testcase #637.87 us52 KBAcceptedScore: 0

Subtask #1 Testcase #736.68 us52 KBAcceptedScore: 0

Subtask #1 Testcase #849.658 ms4 MB + 348 KBAcceptedScore: 0

Subtask #1 Testcase #949.426 ms4 MB + 348 KBAcceptedScore: 0

Subtask #1 Testcase #1044.328 ms3 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #1154.907 ms4 MB + 832 KBAcceptedScore: 0

Subtask #1 Testcase #1255.272 ms3 MB + 712 KBAcceptedScore: 0

Subtask #1 Testcase #1335.68 us52 KBAcceptedScore: 0


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