結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー どららどらら
提出日時 2020-05-30 12:40:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 889 ms / 3,500 ms
コード長 2,967 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 173,696 KB
実行使用メモリ 14,160 KB
最終ジャッジ日時 2024-04-25 01:04:58
合計ジャッジ時間 19,883 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 21 ms
5,376 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 13 ms
5,376 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 18 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 871 ms
14,152 KB
testcase_14 AC 874 ms
14,160 KB
testcase_15 AC 872 ms
14,028 KB
testcase_16 AC 874 ms
14,152 KB
testcase_17 AC 889 ms
14,024 KB
testcase_18 AC 870 ms
14,156 KB
testcase_19 AC 871 ms
14,028 KB
testcase_20 AC 870 ms
14,156 KB
testcase_21 AC 867 ms
14,156 KB
testcase_22 AC 871 ms
14,160 KB
testcase_23 AC 874 ms
14,156 KB
testcase_24 AC 867 ms
14,028 KB
testcase_25 AC 870 ms
14,032 KB
testcase_26 AC 870 ms
14,028 KB
testcase_27 AC 870 ms
14,028 KB
testcase_28 AC 878 ms
14,028 KB
testcase_29 AC 813 ms
14,032 KB
testcase_30 AC 813 ms
14,032 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;



template<ll mod, ll primitive_root>
class NTT {
  void bit_reverse(vector<ll>& a){
    int N = a.size();
    int i = 0;
    for(int j=1; j<N-1; j++){
      for(int k=N>>1; k>(i^=k); k>>=1);
      if(j < i) swap(a[i], a[j]);
    }
  }
  ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b!=0){
      d = extgcd(b,a%b,y,x);
      y -= (a/b)*x;
    }else{
      x = 1; y = 0;
    }
    return d;
  }
  ll mod_inv(ll a){
    ll x, y;
    extgcd(a, mod, x, y);
    return (mod + x % mod) % mod;
  }
  ll mod_pow(ll x, ll n){
    if(n==0) return 1;
    ll res = mod_pow(x * x % mod, n / 2);
    if(n & 1) res = res * x % mod;
    return res;
  }
  
  void _calc(vector<ll>& a, int sign){
    int N = a.size();
    ll g = primitive_root;

    ll tmp = (mod - 1) * mod_inv(N) % mod;
    ll h = mod_pow(g, tmp);
    if(sign == -1) h = mod_inv(h);

    bit_reverse(a);
    
    for(int m=1; m<N; m<<=1){
      ll _base = mod_pow(h, N/(2*m));
      ll _w = 1;
      for(int x=0; x<m; x++){
        for(int s=x; s<N; s+=(2*m)){
          ll u = a[s];
          ll d = (a[s+m] * _w) % mod;
          a[s] = (u+d) % mod;
          a[s+m] = (u-d+mod) % mod;
        }
        _w = (_w * _base) % mod;
      }
    }
  }

  void ntt(vector<ll>& in){ _calc(in, 1); }
  void intt(vector<ll>& in){
    _calc(in, -1);
    ll n_inv = mod_inv(in.size());
    for(int i=0; i<in.size(); i++){
      in[i] = (in[i] * n_inv) % mod;
    }
  }

public:
  NTT(){}

  long long get_mod() const { return mod; }

  vector<ll> conv(const vector<ll>& a, const vector<ll>& b){
    vector<ll> _a = a, _b = b;
    int m = a.size() + b.size() - 1;
    int n = 1; while(n < m) n <<= 1;
    _a.resize(n, 0);
    _b.resize(n, 0);
    ntt(_a);
    ntt(_b);
    for(int i=0; i<n; i++) _a[i] = (_a[i] * _b[i]) % mod;
    intt(_a);
    _a.resize(m);
    return _a;
  }
};

NTT<998244353,3> ntt;

vector<ll> solve(const vector<ll>& v, int l, int m, int r){
  if(l == m) return vector<ll>{1, v[l]-1};

  vector<ll> lhs = solve(v, l, (l+m)/2, m);
  vector<ll> rhs = solve(v, m, (m+r)/2, r);
  return ntt.conv(lhs, rhs);
}


int main(){
  int N, Q;
  cin >> N >> Q;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<ll> ret = solve(v, 0, v.size()/2, v.size());
  reverse(ALLOF(ret));

  rep(i,Q){
    int b;
    cin >> b;
    cout << ret[b] << endl;
  }

  return 0;
}
0