結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー pockynypockyny
提出日時 2020-05-30 01:26:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,530 ms / 3,500 ms
コード長 2,454 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 93,336 KB
最終ジャッジ日時 2024-04-24 06:39:09
合計ジャッジ時間 28,267 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,096 KB
testcase_01 AC 4 ms
8,120 KB
testcase_02 AC 4 ms
8,320 KB
testcase_03 AC 29 ms
9,648 KB
testcase_04 AC 20 ms
9,156 KB
testcase_05 AC 21 ms
9,268 KB
testcase_06 AC 18 ms
9,156 KB
testcase_07 AC 17 ms
9,236 KB
testcase_08 AC 20 ms
9,292 KB
testcase_09 AC 23 ms
9,224 KB
testcase_10 AC 12 ms
8,764 KB
testcase_11 AC 17 ms
9,188 KB
testcase_12 AC 11 ms
8,680 KB
testcase_13 AC 1,382 ms
93,212 KB
testcase_14 AC 1,374 ms
93,208 KB
testcase_15 AC 1,372 ms
93,212 KB
testcase_16 AC 1,368 ms
93,332 KB
testcase_17 AC 1,371 ms
93,328 KB
testcase_18 AC 1,371 ms
93,200 KB
testcase_19 AC 1,371 ms
93,080 KB
testcase_20 AC 1,370 ms
93,200 KB
testcase_21 AC 1,530 ms
93,204 KB
testcase_22 AC 1,378 ms
93,332 KB
testcase_23 AC 1,380 ms
93,208 KB
testcase_24 AC 1,361 ms
93,204 KB
testcase_25 AC 1,379 ms
93,204 KB
testcase_26 AC 1,373 ms
93,328 KB
testcase_27 AC 1,368 ms
93,328 KB
testcase_28 AC 1,373 ms
93,208 KB
testcase_29 AC 1,309 ms
93,332 KB
testcase_30 AC 1,314 ms
93,336 KB
testcase_31 AC 4 ms
8,284 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);
}

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