提交记录 8528


用户 题目 状态 得分 用时 内存 语言 代码长度
suika 1002i. 【模板题】多项式乘法 Accepted 100 46.236 ms 6804 KB C++ 1.92 KB
提交时间 评测时间
2019-02-22 21:15:36 2020-08-01 01:20:20
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long ll;
#define mod 998244353
#define N 400050
char buf[100000],*p1,*p2;
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int rd() {
	int x=0; char s=nc();
	while(s<'0') s=nc();
	while(s>='0') x=(((x<<2)+x)<<1)+s-'0',s=nc();
	return x;
}
char pbuf[2000000],*pp=pbuf;
void write(int x) {
	static int sta[20],tp=0;
	do {sta[++tp]=x%10,x/=10;}while(x);
	while(tp)*pp++=sta[tp--]+'0';
	*pp++=' ';
}
int mem[N*20],*ptr=mem;
int qp(int x,int y) {int re=1;for(;y;y>>=1,x=ll(x)*x%mod)if(y&1)re=ll(re)*x%mod; return re;}
int INV(int x) {return qp(x,mod-2);}
void ntt(int *a,int len,int flg) {
	int i,j,k,t,tmp,w,wn;
	for(i=k=0;i<len;i++) {
		if(i>k) swap(a[i],a[k]);
		for(j=len>>1;(k^=j)<j;j>>=1) ;
	}
	for(k=2;k<=len;k<<=1) {
		wn=qp(3,(mod-1)/k);
		t=k>>1; 
		if(flg==-1) wn=INV(wn);
		for(i=0;i<len;i+=k) {
			w=1;  
			for(j=i;j<i+t;j++) {
				tmp=ll(a[j+t])*w%mod;
				a[j+t]=(a[j]-tmp)%mod; 
				a[j]=(a[j]+tmp)%mod; 
				w=ll(w)*wn%mod;
			}
		}
	}
	if(flg==-1) for(tmp=INV(len),i=0;i<len;i++) a[i]=ll(a[i])*tmp%mod;
}
int A[N],B[N];
struct shion {
	int *a,len;
	shion() {}
	shion(int l) {len=l,a=ptr,ptr+=l;}
	void fix(int l) {len=l,a=ptr,ptr+=l;}
	shion operator * (const shion &u) const {
		shion re(len+u.len-1);
		int i,l=1,j;
		if(re.len<=100) {
			for(i=0;i<len;i++)for(j=0;j<u.len;j++) {
				re.a[i+j]=(re.a[i+j]+ll(a[i])*u.a[j])%mod;
			}return re;
		}
		while(l<len+u.len)l<<=1;
		for(i=0;i<len;i++) A[i]=a[i];
		for(i=0;i<u.len;i++) B[i]=u.a[i];
		ntt(A,l,1),ntt(B,l,1);
		for(i=0;i<l;i++) A[i]=ll(A[i])*B[i]%mod;
		ntt(A,l,-1);
		for(i=0;i<re.len;i++) re.a[i]=A[i];
		return re;
	}
};
int n,m;
int main() {
	n=rd(),m=rd();n++,m++;
	int i;
	shion a(n),b(m);
	for(i=0;i<n;i++) a.a[i]=rd();
	for(i=0;i<m;i++) b.a[i]=rd();
	shion c=a*b;
	for(i=0;i<n+m-1;i++) write((c.a[i]+mod)%mod);
	fwrite(pbuf,1,pp-pbuf,stdout);
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #17.61 us32 KBAcceptedScore: 0

Subtask #1 Testcase #245.947 ms6 MB + 500 KBAcceptedScore: 100

Subtask #1 Testcase #320.769 ms2 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #420.843 ms2 MB + 420 KBAcceptedScore: 0

Subtask #1 Testcase #57.89 us32 KBAcceptedScore: 0

Subtask #1 Testcase #67.04 us32 KBAcceptedScore: 0

Subtask #1 Testcase #77.59 us32 KBAcceptedScore: 0

Subtask #1 Testcase #845.07 ms5 MB + 716 KBAcceptedScore: 0

Subtask #1 Testcase #945.067 ms5 MB + 716 KBAcceptedScore: 0

Subtask #1 Testcase #1044.21 ms4 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #1146.236 ms6 MB + 660 KBAcceptedScore: 0

Subtask #1 Testcase #1243.152 ms4 MB + 420 KBAcceptedScore: 0

Subtask #1 Testcase #136.9 us32 KBAcceptedScore: 0


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