/* 未完成 */ #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll MOD=998244353; class NTT{ private: long long int mod; const long long root=3; long long int add(const long long int x, const long long int y) { return (x + y < mod ? x + y : x + y - mod); } long long int sub(const long long int x, const long long int y) { return (x >= y) ? (x - y) : ( mod- y + x); } long long int mul(const long long int x, const long long int y) { return x * y % mod; } long long int mod_pow(long long int x, long long int n) { long long int res = 1; while(n > 0){ if(n & 1){ res = mul(res, x); } x = mul(x, x); n >>= 1; } return res; } long long int inverse(const long long int x) { return mod_pow(x, mod- 2); } void ntt(std::vector& a, const bool rev = false){ unsigned int i, j, k, l, p, q, r, s; const unsigned int size = a.size(); if(size == 1) return; std::vector b(size); r = rev ? ( mod- 1 - ( mod- 1) / size) : ( mod- 1) / size; s = mod_pow(root, r); std::vector kp(size / 2 + 1, 1); for(i = 0; i < size / 2; ++i) kp[i + 1] = mul(kp[i], s); for(i = 1, l = size / 2; i < size; i <<= 1, l >>= 1){ for(j = 0, r = 0; j < l; ++j, r += i){ for(k = 0, s = kp[i * j]; k < i; ++k){ p = a[k + r], q = a[k + r + size / 2]; b[k + 2 * r] = add(p, q); b[k + 2 * r + i] = mul(sub(p, q), s); } } swap(a, b); } if(rev){ s = inverse(size); for(i = 0; i < size; i++){ a[i] = mul(a[i], s); } } } public: NTT(long long int mod_=998244353): mod(mod_){}; // //vector c = ntt(a,b)みたいにして使う std::vector operator()(const std::vector& a, const std::vector& b){ const int size = (int)a.size() + (int)b.size() - 1; long long int t = 1; while(t < size){ t <<= 1; } std::vector A(t, 0), B(t, 0); for(int i = 0; i < (int)a.size(); i++){ A[i] = a[i]; } for(int i = 0; i < (int)b.size(); i++){ B[i] = b[i]; } ntt(A), ntt(B); for (int i = 0; i < t; i++){ A[i] = mul(A[i], B[i]); } ntt(A, true); A.resize(size); return A; } //vector c; // res[j]= ∑(a[i+j]*b[i])(i=[0,b.size())) j=[0,a.size()) std::vector filter(const std::vector& a,const std::vector& b){ std::vector revb=b; int lena=a.size(),lenb=b.size(); assert(lena>=lenb); std::reverse(revb.begin(),revb.end()); std::vector filt=this->operator()(a,revb); std::vector res; for(int i=lenb-1;i divide_and_solve(int left,int right){//f_l(x)からf_r(x)までの積 if(right-left==1){ Vec(v,lli,2,1); v[1]=P[left]; return v; } auto vl=divide_and_solve(left,(left+right)/2); auto vr=divide_and_solve((left+right)/2,right); int ls=vl.size(),rs=vr.size(); Vec(marge,lli,ls+rs-1,0); rep(i,0,ls)rep(j,0,rs){ marge[i+j]+=(vl[i]*vr[j])%mod; marge[i+j]%=mod; } return marge; } */ int main(){ int N,Q; cin>>N>>Q; vector A(N),B(Q); for(int i=0;i>A[i]; } for(int i=0;i>B[i]; } NTT ntt; /* vector p(2*100000+10); for(int i=0;i c; //[left,right) auto dfs=[&](auto f,int left,int right)->vector{ if(right-left==1){ vector res(2,1); res[1]=A[left]; //x^1の係数が1, x^0の係数が return res; } int mid=(left+right)/2; vector vl=f(f,left,mid); vector vr=f(f,mid,right); vector res=ntt(vl,vr); return res; }; vector ans=dfs(dfs,0,N); reverse(ans.begin(),ans.end()); for(int i=0;i