結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー QCFiumQCFium
提出日時 2020-05-29 22:18:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,001 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 171,308 KB
実行使用メモリ 53,488 KB
最終ジャッジ日時 2024-04-23 23:06:03
合計ジャッジ時間 16,988 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 15 ms
6,944 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 13 ms
6,944 KB
testcase_06 AC 10 ms
6,944 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 12 ms
6,944 KB
testcase_09 AC 12 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 756 ms
53,236 KB
testcase_30 AC 753 ms
53,232 KB
testcase_31 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}


template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
	std::vector<int> conv(const std::vector<int> a_, const std::vector<int> b_) {
		std::vector<int> a = a_, b = b_;
		size_t size = 1;
		for (; size < a_.size() + b_.size(); size <<= 1);
		a.resize(size);
		b.resize(size);
		ntt(a, false);
		ntt(b, false);
		for (size_t i = 0; i < size; i++) a[i] = (int64_t) a[i] * b[i] % mod;
		ntt(a, true);
		a.resize(a_.size() + b_.size() - 1);
		return a;
	}
};


int main() {
	int n = ri(), q = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	// {a[i] - 1, 1}
	NTT<998244353, 3> ntt;
	std::vector<int> tree[2 * n];
	for (int i = 0; i < n; i++) tree[i + n] = {(a[i] - 1) % 998244353, 1};
	for (int i = n; --i; ) tree[i] = ntt.conv(tree[i << 1], tree[i << 1 | 1]);
	
	for (int i = 0; i < q; i++) {
		int x = ri();
		printf("%d\n", tree[1][x]);
	}
	return 0;
}
0