poly
DIF-DIT 版:
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 998244353
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define poly vector<modint>
const modint G=3,Ginv=modint(1)/3;
inline poly one(){poly a;a.push_back(1);return a;}
vector<int>rev;
int rts[2100000];
inline int ext(int n){
int k=0;
while((1<<k)<n)++k;return k;
}
inline void init(int k){
int n=1<<k;
rts[0]=1,rts[1<<k]=qpow(31,1<<(21-k)).x;
Rep(i,k,1)rts[1<<(i-1)]=1ull*rts[1<<i]*rts[1<<i]%mod;
For(i,1,n-1)rts[i]=1ull*rts[i&(i-1)]*rts[i&-i]%mod;
}
void ntt(poly&a,int k,int typ){
int n=1<<k;
static ull tmp[2100000];
for(int i=0;i<n;++i)tmp[i]=a[i].x;
if(typ==1){
for(int l=n>>1;l>=1;l>>=1){
ull*k=tmp;
for(int*g=rts;k<tmp+n;k+=(l<<1),++g){
for(ull*x=k;x<k+l;++x){
int o=x[l]%mod*(*g)%mod;
x[l]=*x+mod-o,*x+=o;
}
}
}
for(int i=0;i<n;++i)a[i].x=tmp[i]%mod;
}else{
for(int l=1;l<n;l<<=1){
ull*k=tmp;
for(int*g=rts;k<tmp+n;k+=(l<<1),++g){
for(ull*x=k;x<k+l;++x){
int o=x[l]%mod;
x[l]=(*x+mod-o)*(*g)%mod,*x+=o;
}
}
}
int iv=qpow(n,mod-2).x;
for(int i=0;i<n;++i)a[i].x=tmp[i]%mod*iv%mod;
reverse(a.begin()+1,a.end());
}
}
poly operator +(poly a,poly b){
int n=max(a.size(),b.size());a.resize(n),b.resize(n);
For(i,0,n-1)a[i]+=b[i];return a;
}
poly operator -(poly a,poly b){
int n=max(a.size(),b.size());a.resize(n),b.resize(n);
For(i,0,n-1)a[i]-=b[i];return a;
}
poly operator *(poly a,modint b){
int n=a.size();
For(i,0,n-1)a[i]*=b;return a;
}
poly operator *(poly a,poly b){
if(!a.size()||!b.size())return {};
if((int)a.size()<=32 || (int)b.size()<=32){
poly c(a.size()+b.size()-1,0);
for(int i=0;i<a.size();++i)for(int j=0;j<b.size();++j)c[i+j]+=a[i]*b[j];
return c;
}
int n=(int)a.size()+(int)b.size()-1,k=ext(n);
a.resize(1<<k),b.resize(1<<k);
ntt(a,k,1),ntt(b,k,1);
For(i,0,(1<<k)-1)a[i]*=b[i];
ntt(a,k,-1),a.resize(n);return a;
}
poly Tmp;
poly pmul(poly a,poly b,int n,bool ok=0)
{
int k=ext(n);
a.resize(1<<k),ntt(a,k,1);
if(!ok) b.resize(1<<k),ntt(b,k,1),Tmp=b;
For(i,0,(1<<k)-1)a[i]*=Tmp[i];
ntt(a,k,-1),a.resize(n);
return a;
}
poly inv(poly a,int n)
{
a.resize(n);
if(n==1){
poly f(1,1/a[0]);
return f;
}
poly f0=inv(a,(n+1)>>1),f=f0;
poly now=pmul(a,f0,n,0);
for(int i=0;i<f0.size();++i)now[i]=0;
now=pmul(now,poly(0),n,1);
f.resize(n);
for(int i=f0.size();i<n;++i)f[i]=-now[i];
return f;
}
poly inv(poly a){return inv(a,a.size());}
poly deriv(poly a){
int n=(int)a.size()-1;
For(i,0,n-1)a[i]=a[i+1]*(i+1);
a.resize(n);return a;
}
poly inter(poly a){
int n=a.size()+1;a.resize(n); initC(n);
Rep(i,n-1,1)a[i]=a[i-1]*iv[i];
a[0]=0;return a;
}
poly ln(poly a){
int n=a.size();
a=deriv(a)*inv(a),a.resize(n-1);return inter(a);
}
poly exp(poly a,int k){
int n=1<<k;a.resize(n);
if(n==1)return one();
poly f0=exp(a,k-1);f0.resize(n);
return f0*(one()+a-ln(f0));
}
poly exp(poly a){
int n=a.size();
a=exp(a,ext(n));a.resize(n);return a;
}
poly div(poly a,poly b){
int n=a.size(),m=b.size(),k=ext(n-m+1);
reverse(a.begin(),a.end()),reverse(b.begin(),b.end());
a.resize(n-m+1),b.resize(n-m+1);
a=a*inv(b),a.resize(n-m+1),reverse(a.begin(),a.end()); return a;
}
poly modulo(poly a,poly b){
if(b.size()>a.size())return a;
int n=b.size()-1;
a=a-div(a,b)*b;a.resize(n);return a;
}
#define maxn 200005
#define inf 0x3f3f3f3f
signed main()
{
init(21);
int n=read()+1,m=read()+1;
poly f(n),g(m);
for(auto&x:f)x=read();
for(auto&x:g)x=read();
f=f*g;
for(auto x:f)printf("%d ",x.x);
return 0;
}
poly sqrt(poly a,int k){
int n=1<<k;a.resize(n);
if(n==1)return one();
poly f0=sqrt(a,k-1);f0.resize(n);
poly tmp=a*inv(f0);tmp.resize(n);tmp=tmp+f0;
tmp=tmp*((mod+1)/2);
return tmp;
}
poly sqrt(poly a){
int n=a.size();
a=sqrt(a,ext(n));a.resize(n);return a;
}
poly valF;
vector<poly>solveE(int l,int r){
if(l==r)return {{valF[l]},{1,(mod-l)%mod}};
int mid=l+r>>1;
auto fl=solveE(l,mid),fr=solveE(mid+1,r);
return {fl[0]*fr[1]+fl[1]*fr[0],fl[1]*fr[1]};
}
poly transE(poly f){
int n=f.size();valF=f;
vector<poly>g=solveE(0,n-1);
poly res=g[0]*inv(g[1]); res.resize(n);
For(i,0,n-1)res[i]*=ifac[i];
return res;
}
poly shift(poly f,modint v){
int n=f.size(); poly g(n); initC(n);
For(i,0,n-1)f[i]*=fac[i];
modint pw=1;
For(i,0,n-1)g[i]=ifac[i]*pw,pw*=v;
reverse(f.begin(),f.end()),f=f*g,reverse(f.begin(),f.end());
f.resize(n);
For(i,0,n-1)f[i]*=ifac[i];
return f;
}
poly mult(poly a,poly b){
int n=a.size();
reverse(a.begin(),a.end());
a=a*b,a.resize(n);reverse(a.begin(),a.end());return a;
}
```cpp
namespace eva{
poly A[maxn<<2],f;
modint x[maxn],y[maxn];
void dfs1(int p,int l,int r){
if(l==r)return A[p]={1,-x[l]},void();
int mid=l+r>>1;
dfs1(p<<1,l,mid),dfs1(p<<1|1,mid+1,r),A[p]=A[p<<1]*A[p<<1|1];
}
void dfs2(int p,int l,int r,poly f){
if(l==r)return y[l]=f[0],void();
int mid=l+r>>1; f.resize(r-l+1);
if(r-l+1<=64){
dfs2(p<<1,l,mid,mult(f,A[p<<1|1]));
dfs2(p<<1|1,mid+1,r,mult(f,A[p<<1]));
return;
}
reverse(f.begin(),f.end());
int k=ext(f.size()+max(A[p<<1].size(),A[p<<1|1].size())); init(k);
f.resize(1<<k),A[p<<1].resize(1<<k),A[p<<1|1].resize(1<<k);
ntt(f,k,1),ntt(A[p<<1],k,1),ntt(A[p<<1|1],k,1);
poly fr(1<<k);
For(i,0,(1<<k)-1)fr[i]=f[i]*A[p<<1|1][i],f[i]*=A[p<<1][i];
ntt(f,k,-1),ntt(fr,k,-1);
f.resize(r-l+1),fr.resize(r-l+1),reverse(f.begin(),f.end()),reverse(fr.begin(),fr.end());
dfs2(p<<1,l,mid,fr);
dfs2(p<<1|1,mid+1,r,f);
}
void work(poly f,int m){
dfs1(1,1,m);
f.resize(max((int)f.size(),m+1));
A[1].resize(f.size());
dfs2(1,1,m,mult(f,inv(A[1])));
}
}