結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー kappybarkappybar
提出日時 2020-09-14 13:49:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,099 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 175,628 KB
実行使用メモリ 24,220 KB
最終ジャッジ日時 2023-09-04 00:40:51
合計ジャッジ時間 8,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
24,220 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 106 ms
4,376 KB
testcase_04 AC 55 ms
4,380 KB
testcase_05 AC 59 ms
4,380 KB
testcase_06 AC 52 ms
4,380 KB
testcase_07 AC 50 ms
4,376 KB
testcase_08 AC 56 ms
4,380 KB
testcase_09 AC 65 ms
4,376 KB
testcase_10 AC 27 ms
4,376 KB
testcase_11 AC 50 ms
4,380 KB
testcase_12 AC 25 ms
4,380 KB
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>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 998244353;
constexpr double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        ModInt b=*this;
        while(n>0){
            if(n&1) a*=b;
            b*=b;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

class NumberTheoreticalTransform{
    private:
    static void fft(vector<mint>& F){
        int fdeg = F.size();
        if(fdeg == 1) return;
        vector<mint> even,odd;
        for(int i = 0;i < fdeg/2;i++){
            even.push_back(F[i<<1]);
            odd.push_back(F[(i<<1)|1]);
        }
        fft(even);fft(odd);
        mint x = 1,zeta = mint(3).pow((MOD-1)/fdeg); // 3 is primitive root of MOD(998244353)
        for(int i=0;i<fdeg;i++){
            F[i] = even[i % (fdeg/2)] + x * odd[i % (fdeg/2)];
            x *= zeta;
        }
    }

    static void ifft(vector<mint>& F){
        int fdeg = F.size();
        if(fdeg == 1) return;
        vector<mint> even,odd;
        for(int i = 0;i < fdeg/2;i++){
            even.push_back(F[i<<1]);
            odd.push_back(F[i<<1|1]);
        }
        ifft(even),ifft(odd);
        mint x = 1,zeta = mint(3).pow((MOD-1)/fdeg).inv();
        for(int i=0;i<fdeg;i++){
            F[i] = even[i % (fdeg/2)] + x * odd[i % (fdeg/2)];
            x *= zeta;
        }
    }

    public:
    static vector<mint> multiply(vector<mint> F,vector<mint> G){
        int degree = 1;
        while(degree < (int)F.size() + (int)G.size() - 1) degree <<= 1;
        vector<mint> nF(degree,0),nG(degree,0);
        for(int i=0;i<(int)F.size();i++){
            nF[i] = F[i];
        }
        for(int i=0;i<(int)G.size();i++){
            nG[i] = G[i];
        }
        fft(nF),fft(nG);
        for(int i=0;i<degree;i++){
            nF[i] *= nG[i];
        }
        ifft(nF);
        vector<mint> ans((int)(F.size() + G.size() - 1),0);
        mint inv_degree = mint(degree).inv();
        for(int i = 0;i < (int)F.size() + (int)G.size() - 1;i++){
            ans[i] = (nF[i] * inv_degree).x;
        }
        return ans;
    }
};


vector<vector<mint>> seg;

vector<mint> dfs(int l,int r){
    if(l==r) return {1};
    else if(l+1==r) return seg[l];
    else return NumberTheoreticalTransform::multiply(dfs(l,(l+r)/2),dfs((l+r)/2,r));
}

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    seg.resize(n);
    rep(i,n){
        ll a;
        scanf("%lld",&a);
        mint aa = mint(a);
        aa -= 1;
        seg[i] = {aa,1};
    }
    vector<mint> res = dfs(0,n);

    while(q--){
        int b;
        cin >> b;
        cout << res[b] << '\n';
    }
    return 0;
}

0