結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー sugarrrsugarrr
提出日時 2020-05-29 22:11:12
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,182 bytes
コンパイル時間 2,578 ms
コンパイル使用メモリ 165,416 KB
実行使用メモリ 13,896 KB
最終ジャッジ日時 2024-05-07 21:39:54
合計ジャッジ時間 15,210 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,652 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


/*
#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
*/


typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////



namespace NTT { // stanicさん
    std::vector<int> tmp;
    size_t sz = 1;

    inline int powMod(int n, int p, int m) {
        int res = 1;
        while (p) {
            if (p & 1) res = (ll)res * n % m;
            n = (ll)n * n % m;
            p >>= 1;
        }
        return (int)res;
    }
    inline int invMod(int n, int m) {
        return powMod(n, m - 2, m);
    }

    template <int Mod, int PrimitiveRoot>
    struct NTTPart {
        static std::vector<int> ntt(std::vector<int> a, bool inv = false) {
            size_t mask = sz - 1;
            size_t p = 0;
            for (size_t i = sz >> 1; i >= 1; i >>= 1) {
                auto& cur = (p & 1) ? tmp : a;
                auto& nex = (p & 1) ? a : tmp;
                int e = powMod(PrimitiveRoot, (Mod - 1) / sz * i, Mod);
                if (inv) e = invMod(e, Mod);
                int w = 1;
                for (size_t j = 0; j < sz; j += i) {
                    for (size_t k = 0; k < i; ++k) {
                        nex[j + k] = (cur[((j << 1) & mask) + k] + (ll)w * cur[(((j << 1) + i) & mask) + k]) % Mod;
                    }
                    w = (ll)w * e % Mod;
                }
                ++p;
            }
            if (p & 1) std::swap(a, tmp);
            if (inv) {
                int invSz = invMod(sz, Mod);
                for (size_t i = 0; i < sz; ++i) a[i] = (ll)a[i] * invSz % Mod;
            }
            return a;
        }
        static std::vector<int> mul(std::vector<int> a, std::vector<int> b) {
            a = ntt(a);
            b = ntt(b);
            for (size_t i = 0; i < sz; ++i) a[i] = (ll)a[i] * b[i] % Mod;
            a = ntt(a, true);
            return a;
        }
    };

    constexpr int M[] = { 1224736769, 469762049, 167772161 };
    constexpr int PR[] = { 3, 3, 3 };
    constexpr int NTT_CONVOLUTION_TIME = 1;

    inline void garner(std::vector<int> *c, int mod) {
        if (NTT_CONVOLUTION_TIME == 1) {
            for (auto& x : c[0]) x %= mod;
        }
        else if (NTT_CONVOLUTION_TIME == 2) {
            const int r01 = invMod(M[0], M[1]);
            for (size_t i = 0; i < sz; ++i) {
                c[1][i] = (c[1][i] - c[0][i]) * (ll)r01 % M[1];
                if (c[1][i] < 0) c[1][i] += M[1];
                c[0][i] = (c[0][i] + (ll)c[1][i] * M[0]) % mod;
            }
        }
        else if (NTT_CONVOLUTION_TIME == 1) {
            const int R01 = invMod(M[0], M[1]);
            const int R02 = invMod(M[0], M[2]);
            const int R12 = invMod(M[1], M[2]);
            const int M01 = (ll)M[0] * M[1] % mod;
            for (size_t i = 0; i < sz; ++i) {
                c[1][i] = (c[1][i] - c[0][i]) * (ll)R01 % M[1];
                if (c[1][i] < 0) c[1][i] += M[1];
                c[2][i] = ((c[2][i] - c[0][i]) * (ll)R02 % M[2] - c[1][i]) * R12 % M[2];
                if (c[2][i] < 0) c[2][i] += M[2];
                c[0][i] = (c[0][i] + (ll)c[1][i] * M[0] + (ll)c[2][i] * M01) % mod;
            }
        }
    }
    std::vector<int> mul(std::vector<int> a, std::vector<int> b, int mod) {
        for (auto& x : a) x %= mod;
        for (auto& x : b) x %= mod;

        size_t m = a.size() + b.size() - 1;
        sz = 1;
        while (m > sz) sz <<= 1;
        tmp.resize(sz);
        a.resize(sz, 0);
        b.resize(sz, 0);

        std::vector<int> c[NTT_CONVOLUTION_TIME];
        if (NTT_CONVOLUTION_TIME >= 1) c[0] = NTTPart<M[0], PR[0]>::mul(a, b);
        if (NTT_CONVOLUTION_TIME >= 2) c[1] = NTTPart<M[1], PR[1]>::mul(a, b);
        if (NTT_CONVOLUTION_TIME >= 3) c[2] = NTTPart<M[2], PR[2]>::mul(a, b);
        for (auto& v : c) v.resize(m);
        garner(c, mod);
        return c[0];
    }
};

int SOLVE(){
    /*a.pb(1);a.pb(2);
    b.pb(1);b.pb(4);
    auto c(NTT::mul(a, b, i_7));
    for(auto x:c)cout<<x<<" ";*/
    ll n,q;cin>>n>>q;
    vector<int>c;c.pb(1);
    rep(zx,0,n-1){
        vector<int>a(2);
        a[0]=1;cin>>a[1];
        a[1]--;
        c=NTT::mul(a,c,i_7);
    }
    //for(auto x:c)cout<<x<<" ";
    rep(i,0,q-1){
        ll t;cin>>t;
        cout<<c[n-t]<<endl;
    }
    
    return 0;
}



int main(){fastio
    clock_t start = clock();
    SOLVE();
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    cerr<<endl<<time<<"ms"<<endl;
    
    return 0;
}
0