NTT好像是比FFT快了不少
然而感觉不是很看得懂……主要是点值转化为系数表示那里……
upd:大概已经搞明白是个什么玩意儿了……吧……
1 //minamoto 2 #include<bits/stdc++.h> 3 #define R register 4 #define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i) 5 #define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i) 6 #define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v) 7 using namespace std; 8 char buf[1<<21],*p1=buf,*p2=buf; 9 inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;} 10 int read(){ 11 R int res,f=1;R char ch; 12 while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1); 13 for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0'); 14 return res*f; 15 } 16 char sr[1<<21],z[20];int C=-1,Z=0; 17 inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;} 18 void print(R int x){ 19 if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; 20 while(z[++Z]=x%10+48,x/=10); 21 while(sr[++C]=z[Z],--Z);sr[++C]=' '; 22 } 23 const int N=3e6+5,P=998244353,Gi=332748118; 24 inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;} 25 inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;} 26 inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;} 27 int ksm(int x,int y){ 28 R int res=1; 29 for(;y;y>>=1,x=mul(x,x))if(y&1)res=mul(res,x); 30 return res; 31 } 32 int A[N],B[N],O[N],r[N],lim=1,n,m,l; 33 void NTT(int *A,int ty){ 34 fp(i,0,lim-1)if(i<r[i])swap(A[i],A[r[i]]); 35 for(R int mid=1;mid<lim;mid<<=1){ 36 int D=(mid<<1),Wn=ksm(ty==1?3:Gi,(P-1)/D);O[0]=1; 37 fp(i,1,mid-1)O[i]=mul(O[i-1],Wn); 38 for(R int j=0;j<lim;j+=D){ 39 for(R int k=0;k<mid;++k){ 40 int x=A[j+k],y=mul(O[k],A[j+k+mid]); 41 A[j+k]=add(x,y),A[j+k+mid]=dec(x,y); 42 } 43 } 44 } 45 if(ty==-1)for(R int i=0,inv=ksm(lim,P-2);i<lim;++i)A[i]=mul(A[i],inv); 46 } 47 int main(){ 48 // freopen("testdata.in","r",stdin); 49 n=read(),m=read();while(lim<=n+m)lim<<=1,++l; 50 fp(i,0,lim-1)r[i]=(r[i>>1]>>1)|((i&1)<<(l-1)); 51 fp(i,0,n)A[i]=read();fp(i,0,m)B[i]=read(); 52 NTT(A,1),NTT(B,1); 53 fp(i,0,lim-1)A[i]=mul(A[i],B[i]); 54 NTT(A,-1); 55 fp(i,0,n+m)print(A[i]);return Ot(),0; 56 }