結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー harady_a_humanharady_a_human
提出日時 2020-05-29 20:41:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,415 ms / 3,500 ms
コード長 3,129 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 172,480 KB
実行使用メモリ 29,560 KB
最終ジャッジ日時 2024-04-23 19:58:12
合計ジャッジ時間 28,411 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 28 ms
5,376 KB
testcase_04 AC 18 ms
5,376 KB
testcase_05 AC 19 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 15 ms
5,376 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 20 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 1,387 ms
29,428 KB
testcase_14 AC 1,392 ms
29,428 KB
testcase_15 AC 1,389 ms
29,428 KB
testcase_16 AC 1,415 ms
29,460 KB
testcase_17 AC 1,390 ms
29,532 KB
testcase_18 AC 1,390 ms
29,432 KB
testcase_19 AC 1,394 ms
29,428 KB
testcase_20 AC 1,394 ms
29,432 KB
testcase_21 AC 1,385 ms
29,436 KB
testcase_22 AC 1,389 ms
29,556 KB
testcase_23 AC 1,395 ms
29,556 KB
testcase_24 AC 1,389 ms
29,436 KB
testcase_25 AC 1,392 ms
29,432 KB
testcase_26 AC 1,388 ms
29,432 KB
testcase_27 AC 1,388 ms
29,556 KB
testcase_28 AC 1,391 ms
29,560 KB
testcase_29 AC 1,327 ms
29,428 KB
testcase_30 AC 1,331 ms
29,524 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define UNIQUE(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define Double double

using ll = long long;
const ll mod = 998244353;

#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)

typedef pair<int, int> Pii;

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 mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

template<int mod, int primitive_root>
class NTT {
public:
	int get_mod() const { return mod; }
	void _ntt(vector<ll>& a, int sign) {
		const int n = sz(a);
		assert((n ^ (n&-n)) == 0); //n = 2^k

		const int g = 3; //g is primitive root of mod
		int h = (int)mod_pow(g, (mod - 1) / n, mod); // h^n = 1
		if (sign == -1) h = (int)mod_inv(h, mod); //h = h^-1 % mod

		//bit reverse
		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]);
		}

		for (int m = 1; m < n; m *= 2) {
			const int m2 = 2 * m;
			const ll base = mod_pow(h, n / m2, mod);
			ll w = 1;
			rep(x, m) {
				for (int s = x; s < n; s += m2) {
					ll u = a[s];
					ll d = a[s + m] * w % mod;
					a[s] = u + d;
					if (a[s] >= mod) a[s] -= mod;
					a[s + m] = u - d;
					if (a[s + m] < 0) a[s + m] += mod;
				}
				w = w * base % mod;
			}
		}

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

	// 畳み込み演算を行う
	vector<ll> convolution(const vector<ll>& a, const vector<ll>& b){
		int ntt_size = 1;
		while (ntt_size < sz(a) + sz(b)) ntt_size *= 2;

		vector<ll> _a = a, _b = b;
		_a.resize(ntt_size); _b.resize(ntt_size);

		ntt(_a);
		ntt(_b);

		rep(i, ntt_size){
			(_a[i] *= _b[i]) %= mod;
		}

		intt(_a);
		return _a;
	}
};

NTT<998244353, 3> ntt;

vector<ll> A;
vector<ll> saiki(int l, int r) {
    if (r == l + 1) return vector<int>{A[l], 1};
    vector<ll> tL = saiki(l, (l+r)/2), tR = saiki((l+r)/2, r);
    vector<ll> L, R;
    for (auto &&elm : tL) L.pb(elm);
    for (auto &&elm : tR) R.pb(elm);
    return ntt.convolution(L, R);
}
 
signed main() {
    int n; cin >> n; int m; cin >> m;
    A.resize(n); rep (i, n) cin >> A[i], A[i]--, A[i] %= mod;
    auto ans = saiki(0, n);
    rep (i, m) {
      int a; cin >> a;
      cout << ans[a] << endl;
    }
}
0