• 2017 Multi-University Training Contest


    题解:

    我是参考的

    http://blog.csdn.net/qq_32570675/article/details/76571666

    这一篇

    orz 原来可以这么变换,涨姿势

    代码:

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    typedef long long LL;
    const int maxn = 1e5 + 100;
    const int g = 3;
    const int MOD = 998244353;
    LL F[maxn*8], G[maxn*8], mul[maxn], imul[maxn], ans[maxn], qp[maxn];
    int a[maxn];
    
    LL mypow(LL a, LL b){
        LL ans = 1; for(; b; b >>= 1) { if(b&1) (ans *= a) %= MOD; (a *= a) %= MOD; } return ans;
    }
    
    void Modify(LL *a, int L){
        for(int i = 1, j = L/2; i < L-1; i++){
            if(i < j) swap(a[i], a[j]);
            int k = L/2;
            while(j >= k){
                j -= k;
                k >>= 1;
            }
            if(j < k) j += k;
        }
    }
    
    void NTT(LL *y, int L, int ty){
        Modify(y, L);
        int id = 0;
        for(int h = 2; h <= L; h <<= 1){
            id++;
            for(int j = 0; j < L; j += h){
                LL w = 1;
                for(int k = j; k < j + h/2; k++){
                    LL u = y[k];
                    LL t = y[k+h/2]*w%MOD;
                    y[k] = (u+t)%MOD;
                    y[k+h/2] = (u-t+MOD)%MOD;
                    w = w*qp[id]%MOD;
                }
            }
        }
        if(ty == -1){
            for(int i = 1; i < L/2; i++) swap(y[i], y[L-i]);
            LL inv = mypow(L, MOD-2);
            for(int i = 0; i < L; i++)
                y[i] = y[i]*inv%MOD;
        }
    }
    
    
    
    void init(){
        int n = 1e5 + 10;
        mul[0] = imul[0] = mul[1] = 1;
        for(int i = 2; i <= n; i++) mul[i] = (mul[i-1]*i)%MOD;
        for(int i = 1; i <= n; i++) imul[i] = mypow(mul[i], MOD-2);
        for(int i = 0; i < 21; i++){
            int t = 1<<i;
            qp[i] = mypow(g, (MOD-1)/t);
        }
    }
    
    int main()
    {
        init();
        int n, m, x;
        while(cin>>n){
            for(int i = 0; i <= n; i++) scanf("%d", &a[i]);
            cin>>m;
            LL b = 0;
            for(int i = 1; i <= m; i++){
                scanf("%d", &x);
                b -= x;
                (b += MOD) %= MOD;
            }
            memset(F, 0, sizeof(F));
            memset(G, 0, sizeof(G));
            for(int i = 0; i <= n; i++){
                F[i] = a[n-i]*mul[n-i]%MOD;
                G[i] = mypow(b, i)*imul[i]%MOD;
            }
            int L = 1, nn = (n+1)<<1;
            while(L < nn) L <<= 1;
            NTT(F, L, 0); NTT(G, L, 0);
            for(int i = 0; i < L; i++){
                F[i] = (F[i]*G[i])%MOD;
            }
            NTT(F, L, -1);
            for(int i = 0; i <= n; i++){
                (F[i] += MOD) %= MOD;
                ans[i] = F[n-i]*imul[i]%MOD;
            }
            for(int i = 0; i <= n; i++) printf("%d ", ans[i]);
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    XML 读取器和编写器从URL读取XML
    8月8号 星期五
    080808 晴
    080805
    雨景
    用photoshop批量修改照片(待修改)
    8月7日 晴
    五不
    Android 画渐变的背景
    iOS开发的一些基础知识
  • 原文地址:https://www.cnblogs.com/Saurus/p/7291337.html
Copyright © 2020-2023  润新知