1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define ff(i,j,k) for(int i=(j),end_i=(k);i< end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cerr<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second inline int read() { int x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f?-x:x; } #define CASET fo(___,1,read())
const ll mod=998244353; inline ll Add(ll x,ll y){x+=y; return (x<mod)?x:x-mod;} inline ll Dec(ll x,ll y){x-=y; return (x<0)?x+mod:x;} inline ll Mul(ll x,ll y){return x*y%mod;} inline ll Pow(ll x,ll y) { ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1) ans=ans*x%mod; return ans; }
const int M=1<<19; ll W[M]; inline void PolyInit() { ll w; for(int i=1;i<M;i<<=1) { W[i]=1; w=Pow(3,(mod-1)/2/i); fo(j,1,i-1) W[i+j]=W[i+j-1]*w%mod; } } typedef vector<ll> Poly; inline void print(Poly A) { ff(i,0,A.size()) printf("%d ",A[i]); printf("\n"); } inline void ntt(ll *a,int n,int t) { static int R[M]; fo(i,0,n-1) { R[i]=(R[i>>1]>>1)|((i&1)*(n>>1)); if(i<R[i]) swap(a[i],a[R[i]]); } ll w; for(int i=1;i<n;i<<=1) for(int j=0;j<n;j+=(i<<1)) for(int k=0;k<i;k++) w=W[i+k]*a[i+j+k]%mod, a[i+j+k]=Dec(a[j+k],w), a[j+k]=Add(a[j+k],w); if(t^1) { reverse(a+1,a+n); w=Pow(n,mod-2); fo(i,0,n-1) a[i]=w*a[i]%mod; } } inline void ntt(Poly &A,int n,int t){ntt(&A[0],n,t);} inline Poly operator +(Poly A,Poly B) { A.resize(max(A.size(),B.size())); fo(i,0,B.size()-1) A[i]=Add(A[i],B[i]); return A; } inline Poly operator -(Poly A,Poly B) { A.resize(max(A.size(),B.size())); fo(i,0,B.size()-1) A[i]=Dec(A[i],B[i]); return A; } inline Poly df(Poly A) { fo(i,1,A.size()-1) A[i-1]=A[i]*i%mod; A.resize(A.size()-1); return A; } inline Poly jf(Poly A) { A.pb(0); fd(i,A.size()-1,1) A[i]=A[i-1]*Pow(i,mod-2)%mod; A[0]=0; return A; } inline Poly operator *(Poly A,ll k) { fo(i,0,A.size()-1) A[i]=A[i]*k%mod; return A; } inline Poly operator *(Poly A,Poly B) { int n=A.size(),m=B.size(),k=n+m-1,len=1; for(;len<k;len<<=1); A.resize(len); ntt(A,len,1); B.resize(len); ntt(B,len,1); fo(i,0,len-1) A[i]=A[i]*B[i]%mod; ntt(A,len,-1); A.resize(k); return A; } inline Poly operator ~(Poly f) { int n=f.size(); Poly g,h; g.pb(Pow(f[0],mod-2)); int m=2; for(;m<n;m<<=1) { h.resize(m<<1); g.resize(m<<1); fo(i,0,m-1) h[i]=f[i]; ntt(h,m<<1,1); ntt(g,m<<1,1); fo(i,0,(m<<1)-1) g[i]=Mul(2+mod-Mul(g[i],h[i]),g[i]); ntt(g,m<<1,-1); g.resize(m); } g.resize(m<<1); f.resize(m<<1); ntt(f,m<<1,1); ntt(g,m<<1,1); fo(i,0,(m<<1)-1) g[i]=Mul(2+mod-Mul(g[i],f[i]),g[i]); ntt(g,m<<1,-1); g.resize(n); return g; } const int N=64005; #define lc (u<<1) #define rc ((u<<1)|1) Poly P[N<<2]; ll ans[N],a[N]; inline Poly MulT(Poly A,Poly B) { int n=A.size(),m=B.size(); reverse(all(B)); int len=1; for(;len<n;len<<=1); A.resize(len); B.resize(len); ntt(A,len,1); ntt(B,len,1); ff(i,0,len) A[i]=A[i]*B[i]%mod; ntt(A,len,-1); B.clear(); len--; fo(i,m-1,n+m-2) B.pb(A[i&len]); return B; } void solve(int u,int l,int r) { if(l==r) { P[u].pb(1); P[u].pb(Dec(0,a[l])); return; } int mid=(l+r)>>1; solve(lc,l,mid); solve(rc,mid+1,r); P[u]=P[lc]*P[rc]; } void solve(int u,int l,int r,Poly A) { A.resize(r-l+1); if(l==r) return (void)(ans[l]=A[0]); int mid=(l+r)>>1; solve(lc,l,mid,MulT(A,P[rc])); solve(rc,mid+1,r,MulT(A,P[lc])); } int n,m,k; Poly F,G; int main() { PolyInit(); n=read(); m=read(); k=max(n,m); fo(i,0,n) F.pb(read()); F.resize(n+k+1); fo(i,1,m) a[i]=read(); solve(1,1,k); F=MulT(F,(~P[1])); solve(1,1,k,F); fo(i,1,m) printf("%lld\n",ans[i]); return 0; }
|