QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142621#6187. Digit Sum ProblemSanguineChameleonCompile Error//C++204.1kb2023-08-19 14:17:272023-08-19 14:17:29

Judging History

你现在查看的是最新测评结果

  • [2023-08-19 14:17:29]
  • 评测
  • [2023-08-19 14:17:27]
  • 提交

answer

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

void just_do_it();

int main() {
	#ifdef KAMIRULEZ
		freopen("kamirulez.inp", "r", stdin);
		freopen("kamirulez.out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	just_do_it();
	return 0;
}

const int maxK = 22;

namespace NTT {
	const long long mod = (119 << 23) + 1;

	long long bin_pow(long long x, long long y) {
		long long res = 1;
		while (y) {
			if (y & 1) {
				res = res * x % mod;
			}
			y >>= 1;
			x = x * x % mod;
		}
		return res;
	}

	long long mod_inv(long long x) {
		return bin_pow(x, mod - 2);
	}

	int maxL;
	int maxN;
	long long root;

	void fft(long long A[], bool inv) {
		for (int i = 0; i < maxN; i++) {
			int rev = 0;
			for (int j = 0; j < maxL; j++) {
				rev |= ((i >> j) & 1) << (maxL - 1 - j);
			}
			if (i < rev) {
				swap(A[i], A[rev]);
			}
		}
		for (int len = 2; len <= maxN; len <<= 1) {
			long long mul = (inv ? mod_inv(root) : root);
			for (int tmp = len; tmp < maxN; tmp <<= 1) {
				mul = mul * mul % mod;
			}
			for (int i = 0; i < maxN; i += len) {
				long long cur = 1;
				for (int j = 0; j < (len >> 1); j++) {
					long long X = A[i + j];
					long long Y = A[i + j + (len >> 1)];
					A[i + j] = (X + cur * Y) % mod;
					A[i + j + (len >> 1)] = (X + (mod - cur) * Y) % mod;
					cur = cur * mul % mod;
				}
			}
		}
		if (inv) {
			long long mul = mod_inv(maxN);
			for (int i = 0; i < maxN; i++) {
				A[i] = A[i] * mul % mod;
			}
		}
	}

	long long A[1 << maxK];
	long long B[1 << maxK];

	void mul(long long _A[], long long _B[], long long C[], int _maxL) {
		maxL = _maxL;
		maxN = (1 << maxL);
		root = bin_pow(bin_pow(3, 119), 1 << (23 - maxL));
		for (int i = 0; i < maxN; i++) {
			A[i] = _A[i];
			B[i] = _B[i];
		}
		fft(A, false);
		fft(B, false);
		for (int i = 0; i < maxN; i++) {
			C[i] = A[i] * B[i] % mod;
		}
		fft(C, true);
	}
};

const long long mod = 998244353;
const long long maxN = 1e13 + 20;
const int maxL = 50;
const int block_size = 59049;
const int max_block_cnt = max(block_size, (int)(maxN / block_size)) + 20;
long long pwA_small[block_size];
long long pwA_big[max_block_cnt];
long long ternary[max_block_cnt];
long long pwB[maxL];
long long big[2][1 << maxK];
long long small[1 << maxK];
long long prod[2][1 << maxK];

void just_do_it() {
	long long N, A, B, C;
	cin >> N >> A >> B >> C;
	pwB[0] = 1;
	for (int i = 1; i < maxL; i++) {
		pwB[i] = pwB[i - 1] * B % mod;
	}
	pwA_small[0] = 1;
	for (int i = 1; i < block_size; i++) {
		pwA_small[i] = pwA_small[i - 1] * A % mod;
	}
	pwA_big[0] = 1;
	pwA_big[1] = pwA_small[block_size - 1] * A % mod;
	for (int i = 2; i < max_block_cnt; i++) {
		pwA_big[i] = pwA_big[i - 1] * pwA_big[1] % mod;
	}
	ternary[0] = 1;
	for (int i = 1; i < max_block_cnt; i++) {
		ternary[i] = ternary[i / 3];
		for (int j = 0; j < i % 3; j++) {
			ternary[i] = ternary[i] * C % mod;
		}
	}
	int block_cnt = (N + 1) / block_size;
	int K = 0;
	while ((1 << K) < block_size) {
		K++;
	}
	for (int i = 0; i < block_cnt; i++) {
		long long pref = 1LL * i * block_size;
		int low = (pref & ((1 << K) - 1));
		long long high = (pref >> K);
		big[0][low] = (big[0][low] + pwA_big[i] * ternary[i] % mod * pwB[__builtin_popcountll(high)]) % mod;
		big[1][low] = (big[1][low] + pwA_big[i] * ternary[i] % mod * pwB[__builtin_popcountll(high + 1)]) % mod;
	}
	for (int i = 0; i < block_size; i++) {
		small[i] = (small[i] + pwA_small[i] * ternary[i]) % mod;
	}
	NTT::mul(big[0], small, prod[0], K + 1);
	NTT::mul(big[1], small, prod[1], K + 1);
	long long res = 0;
	for (int i = 0; i < (1 << K); i++) {
		res = (res + pwB[__builtin_popcount(i)] * prod[0][i]) % mod;
		res = (res + pwB[__builtin_popcount(i)] * prod[1][i + (1 << K)]) % mod;
	}
	for (long long i = 1LL * block_cnt * block_size; i <= N; i++) {
		res = (res + pwA_big[block_cnt] * pwA_small[i % block_size] % mod * pwB[__builtin_popcountll(i)] % mod * ternary[block_cnt] % mod * ternary[i % block_size]) % mod;
	}
	res = (res + mod - 1) % mod;
	cout << res;
}

詳細信息

/tmp/cc4TL8T3.o: in function `NTT::fft(long long*, bool)':
answer.code:(.text+0x23c): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::maxN' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0x258): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::maxL' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0x648): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::root' defined in .bss section in /tmp/cc4TL8T3.o
/tmp/cc4TL8T3.o: in function `NTT::mul(long long*, long long*, long long*, int)':
answer.code:(.text+0xe05): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::maxL' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0xe2b): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::maxN' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0xea8): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::root' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0xeb8): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::A' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0xed5): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::B' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0x1525): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::A' defined in .bss section in /tmp/cc4TL8T3.o
answer.code:(.text+0x1533): relocation truncated to fit: R_X86_64_PC32 against symbol `NTT::B' defined in .bss section in /tmp/cc4TL8T3.o
/tmp/cc4TL8T3.o: in function `just_do_it()':
answer.code:(.text+0x1709): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status