結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー ace_amuroace_amuro
提出日時 2021-02-14 14:42:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,183 ms / 3,500 ms
コード長 2,448 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 80,004 KB
実行使用メモリ 51,544 KB
最終ジャッジ日時 2023-09-29 04:34:55
合計ジャッジ時間 26,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,656 KB
testcase_01 AC 4 ms
11,808 KB
testcase_02 AC 4 ms
11,800 KB
testcase_03 AC 25 ms
12,304 KB
testcase_04 AC 18 ms
12,264 KB
testcase_05 AC 20 ms
12,340 KB
testcase_06 AC 16 ms
12,056 KB
testcase_07 AC 15 ms
12,020 KB
testcase_08 AC 20 ms
12,068 KB
testcase_09 AC 22 ms
12,168 KB
testcase_10 AC 11 ms
11,816 KB
testcase_11 AC 15 ms
11,996 KB
testcase_12 AC 10 ms
11,760 KB
testcase_13 AC 1,172 ms
51,540 KB
testcase_14 AC 1,173 ms
51,184 KB
testcase_15 AC 1,179 ms
51,260 KB
testcase_16 AC 1,180 ms
51,180 KB
testcase_17 AC 1,177 ms
51,220 KB
testcase_18 AC 1,177 ms
51,192 KB
testcase_19 AC 1,176 ms
51,184 KB
testcase_20 AC 1,178 ms
51,340 KB
testcase_21 AC 1,176 ms
51,252 KB
testcase_22 AC 1,179 ms
51,280 KB
testcase_23 AC 1,174 ms
51,240 KB
testcase_24 AC 1,177 ms
51,368 KB
testcase_25 AC 1,180 ms
51,500 KB
testcase_26 AC 1,178 ms
51,240 KB
testcase_27 AC 1,182 ms
51,340 KB
testcase_28 AC 1,183 ms
51,364 KB
testcase_29 AC 1,165 ms
51,288 KB
testcase_30 AC 1,168 ms
51,544 KB
testcase_31 AC 4 ms
9,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned int uint;
LL ww[101];
LL* e = ww + 50;
const int MAXN=2e5+5;
const LL P=998244353;

LL qpow(LL a,LL k, LL p){
    LL c=1;
    a %= p;
    while(k){
        if(k&1) c=(c*a)%p;
        k >>= 1;
        a = (a*a)%p;
    }
    return c;
}


void ntt_initial(LL* e, const LL& P, const LL& g) {
    int s = 0; LL q = P - 1;
    while ((q & 1) == 0) {s++; q >>= 1;}
    LL w = qpow(g, q, P);
    LL invw = qpow(w, P - 2, P);
    for (int h = s; h >= 0; h--) {
        e[h] = w;
        e[-h] = invw;
        w = (w * w) % P;
        invw = (invw * invw) % P;
    }
}

void ntt(LL* f, const int& h, const int& type) {
    if (h == 0) return;
    LL f0[1 << (h - 1)], f1[1 << (h - 1)];
    int n = 1 << h;
    for (int i = 0; i < n; i+=2) f0[i/2] = f[i];
    ntt(f0, h - 1, type);
    for (int i = 1; i < n; i+=2) f1[i/2] = f[i];
    ntt(f1, h - 1, type);
    LL w = e[type * h];
    LL x = 1;
    for (int k = 0; k < n / 2; k++) {
        f[k] = f0[k] + x * f1[k];
        f[k] %= P;
        f[k + n / 2] = f0[k] - x * f1[k];
        f[k + n / 2] %= P;
        x *= w; x %= P;
    }
}

LL A[MAXN];
vector<LL> f[MAXN];
LL F1[MAXN*4],F2[MAXN*4];
void mul(int i1,int i2){
    int limit=f[i1].size()+f[i2].size()-1;
    int deg=1,h=0;
    while(deg<limit) {deg<<=1;h++;}
    for(uint i=0;i<f[i1].size();i++) F1[i]=f[i1][i];
    for(int i=f[i1].size();i<deg;i++) F1[i]=0;
    for(uint i=0;i<f[i2].size();i++) F2[i]=f[i2][i];
    for(int i=f[i2].size();i<deg;i++) F2[i]=0;
    ntt(F1,h,1);ntt(F2,h,1);
    for(int i=0;i<deg;i++) F1[i]=F1[i]*F2[i]%P;
    ntt(F1,h,-1);
    LL inv = qpow(deg, P - 2, P);
    for (int i = 0; i < deg; i++) {
        F1[i] = ((F1[i] * inv) % P + P)%P;
    }
    f[i1].clear();
    for(int i=0;i<limit;i++) f[i1].push_back(F1[i]);
}

int main(){
    ntt_initial(e,P,3);
    int n,Q;
    int B;
    scanf("%d%d",&n,&Q);
    for(int i=0;i<n;i++){
        scanf("%lld",A+i);
        A[i]%=P;
        f[i].push_back(A[i]-1);
        f[i].push_back(1);
    }
    while(n>1){
        for(int i=0;i<n/2;i++){
            mul(i,i+n/2);
        }
        if(n&1){
            f[n/2]=f[n-1];
            n=n/2+1;
        }
        else{
            n=n/2;
        }
    }
    for(int i=0;i<Q;i++){
        scanf("%d",&B);
        cout<<f[0][B]<<endl;
    }
    
    return 0;
}
0