結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー pockynypockyny
提出日時 2020-05-30 01:28:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,350 ms / 3,500 ms
コード長 2,480 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 79,692 KB
実行使用メモリ 93,216 KB
最終ジャッジ日時 2023-08-06 10:52:15
合計ジャッジ時間 26,722 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,056 KB
testcase_01 AC 4 ms
8,056 KB
testcase_02 AC 4 ms
8,136 KB
testcase_03 AC 29 ms
9,528 KB
testcase_04 AC 20 ms
9,060 KB
testcase_05 AC 21 ms
8,952 KB
testcase_06 AC 17 ms
8,960 KB
testcase_07 AC 17 ms
8,860 KB
testcase_08 AC 20 ms
8,948 KB
testcase_09 AC 22 ms
9,092 KB
testcase_10 AC 11 ms
8,712 KB
testcase_11 AC 17 ms
8,904 KB
testcase_12 AC 11 ms
8,500 KB
testcase_13 AC 1,331 ms
92,908 KB
testcase_14 AC 1,339 ms
92,956 KB
testcase_15 AC 1,337 ms
92,904 KB
testcase_16 AC 1,348 ms
92,844 KB
testcase_17 AC 1,332 ms
92,844 KB
testcase_18 AC 1,336 ms
93,036 KB
testcase_19 AC 1,338 ms
92,976 KB
testcase_20 AC 1,340 ms
93,036 KB
testcase_21 AC 1,337 ms
92,912 KB
testcase_22 AC 1,346 ms
93,216 KB
testcase_23 AC 1,334 ms
93,036 KB
testcase_24 AC 1,340 ms
92,976 KB
testcase_25 AC 1,343 ms
92,840 KB
testcase_26 AC 1,338 ms
93,204 KB
testcase_27 AC 1,334 ms
92,840 KB
testcase_28 AC 1,350 ms
93,044 KB
testcase_29 AC 1,289 ms
93,024 KB
testcase_30 AC 1,290 ms
93,048 KB
testcase_31 AC 4 ms
8,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int gen = 3;
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }
ll pw(ll a, ll b){
    ll x = 1;
    while (b){
        while(!(b&1)){
            (a *= a) %= mod; b /= 2;
        }
        (x *= a) %= mod; b--;
    }
    return x;
}

void _ntt(vector <ll> &a,int sign) {
    int i,j,k,n = a.size(),m = 1;
    while(m<n || m==1) m <<= 1;
    a.resize(m); n = m;
    const int g = 3;
    ll h = pw(g,(mod - 1)/n);
    if(sign==-1) h = (int)mod_inv(h,mod);
    i = 0;
    for(j=1;j<n - 1;j++) {
        for(k=(n >> 1); k>(i ^= k); k >>= 1);
        if(j<i) swap(a[i],a[j]);
    }
    for(i=1;i<n;i*= 2){
        const int i2 = 2*i;
        const ll base = pw(h,n/i2);
        ll w = 1;
        for(j=0;j<i;j++){
            for(k=j;k<n;k += i2){
                ll u = a[k];
                ll d = a[k + i]*w%mod;
                a[k] = u + d;
                if(a[k]>=mod) a[k] -= mod;
                a[k + i] = u - d;
                if(a[k + i]<0) a[k + i] += mod;
            }
            (w *= base) %= mod;
        }
    }
    for(ll x: a){
        if(x<0) x += mod;
    }
}

void ntt(vector<ll>& input) {
	_ntt(input, 1);
}
void intt(vector<ll>& input) {
	_ntt(input, -1);
    ll x = input.size();
	const int n_inv = mod_inv(x, mod);
	for (auto& x : input) x = x * n_inv % mod;
}

void multiply(vector<ll> & input1,vector<ll> & input2){
    int l = input1.size(),r = input2.size();
    int s = 1;
    while(s<l + r) s <<= 1;
    input1.resize(s); input2.resize(s);
    ntt(input1); ntt(input2);
    for(int i=0;i<input1.size();i++){
        (input1[i] *= input2[i]) %= mod;
    }
    intt(input1);
    input1.resize(l + r);
}

vector<ll> v[200010];
void solve(int l,int r){
    if(l==r) return;
    if(r - l==1){
        multiply(v[l],v[r]);
        return ;
    }
    solve(l,(l + r)/2); solve((l + r)/2 + 1,r);
    multiply(v[l],v[(l + r)/2 + 1]);
}

int main(){
    int i,n,q;
    cin >> n >> q;
    for(i=0;i<n;i++){
        ll a; cin >> a;
        v[i].push_back((a - 1 + mod)%mod); v[i].push_back(1);
    }
    solve(0,n - 1);
    for(i=0;i<q;i++){
        int b; cin >> b;
        cout << v[0][b] << endl;
    }
}
0