Problem:
Score : 100 points

Problem Statement

You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.

Constraints

1 \leq N, M \leq 524288

0 \leq a_i, b_i < 998244353

All values in Input are integer.

Input

Input is given from Standard Input in the following format:

N M
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{M-1}

Output

Print the answer in the following format:

c_0 c_1 ... c_{(N - 1) + (M - 1)}

Sample Input 1

4 5
1 2 3 4
5 6 7 8 9

Sample Output 1

5 16 34 60 70 70 59 36

Sample Input 2

1 1
10000000
10000000

Sample Output 2

871938225

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
/*----------------------------------ここからマクロ----------------------------------*/
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(int i=0;i<(int)n;++i)
#define rep2(i,n) for(int i=0;i<(int)n;++i)
#define rep3(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define rep4(i,a,b,c) for(int i=(int)a;i<(int)b;i+=(int)c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#ifdef _DEBUG
#define debug1(a) cerr << #a << ": " << a << "\n"
#define debug2(a,b) cerr << #a << ": " << a << ", " << #b << ": " << b << "\n"
#define debug3(a,b,c) cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " << c << "\n"
#define debug4(a,b,c,d) cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " << c << ", " << #d << ": " << d << "\n"
#define debug(...) overload4(__VA_ARGS__,debug4,debug3,debug2,debug1)(__VA_ARGS__)
#define vecout(a) cerr << #a << ": [";rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "":",");}cerr << "]\n"
#else
#define debug(...)
#define vecout(a)
#endif
#define mp make_pair
//#define doset(x) cout << fixed << setprecision(x)
struct doset{doset(int n){cout << fixed << setprecision(n);cerr << fixed << setprecision(n);}};
struct myset{myset(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}};
using ll = long long;
using ld = long double;
using dou = double;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod1 = 1000000007LL;
const ll mod2 = 998244353LL;
typedef pair<ll,ll> P;
template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
    bool res = true;
    if(n == 1 || n == 0)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

template<class T = int>
T in(){T x;cin >> x;return x;}

inline bool Yes(bool b){cout << (b ? "Yes\n":"No\n");return b;}
inline bool YES(bool b){cout << (b ? "YES\n":"NO\n");return b;}

/*----------------------------------マクロここまで----------------------------------*/

struct NumberTheoriticalTransform{
    ll MOD,base,max_exp;
    vector<ll> bases,invs;//~[i]:MODの2*i乗根（のinv）
    NumberTheoriticalTransform(ll MOD_,ll base_,ll max_exp_):MOD(MOD_),base(base_),max_exp(max_exp_),bases(max_exp_ + 1),invs(max_exp_ + 1){
        bases[max_exp] = base;
        invs[max_exp] = modpow(base,MOD - 2,MOD);
        for(int i = max_exp - 1;i >= 0;i--){
            bases[i] = bases[i + 1] * bases[i + 1] % MOD;
            invs[i] = invs[i + 1] * invs[i + 1] % MOD;
        }
    }
    int exp(int s){
        int res = 0;
        s >>= 1;
        while(s){
            res++;
            s >>= 1;
        }
        return res;
    }

    void dft(vector<ll> &func,int inv){
        int sz = func.size();
        if(sz == 1)return;
        vector<ll> veca,vecb;
        rep(i,sz / 2){
            veca.push_back(func[i * 2]);
            vecb.push_back(func[i * 2 + 1]);
        }
        dft(veca,inv);
        dft(vecb,inv);
        ll now = 1,zeta = (inv == 1 ? bases[exp(sz)]:invs[exp(sz)]);
        rep(i,sz){
            func[i] = ((veca[i % (sz / 2)] + now * vecb[i % (sz / 2)]) % MOD + MOD) % MOD;
            now *= zeta;
            now %= MOD;
        }
    }
    vector<ll> multiply(vector<ll> f,vector<ll> g){
        int sz = 1;
        while(sz < f.size() + g.size())sz <<= 1;
        vector<ll> nf(sz),ng(sz);
        rep(i,f.size()){
            nf[i] = f[i];
            ng[i] = g[i];
        }
        dft(nf,1);
        dft(ng,1);
        rep(i,sz)nf[i] = nf[i] * ng[i] % MOD;
        dft(nf,-1);
        vector<ll> res(sz);
        ll inv = modpow(sz,MOD - 2,MOD);
        rep(i,sz){
            res[i] = nf[i] * inv % MOD;
        }
        return res;
    }
};

int main(){
    myset m;
    NumberTheoriticalTransform NTT(mod2,31,23);
    ll N,M;
    cin >> N >> M;
    ll ms = max(N,M);
    vector<ll> A(ms),B(ms);
    rep(i,N)cin >> A[i];
    rep(i,M)cin >> B[i];
    vector<ll> ans = NTT.multiply(A,B);
    rep(i,N + M - 1)cout << ans[i] << (i == N + M - 2 ? "\n":" ");
    //mod2,31,23
}