这个做法的复杂度是正确的吗
查看原帖
这个做法的复杂度是正确的吗
1697870
qwqerty楼主2025/7/21 14:14

昨天晚上在宿舍里想出来的做法,因为 AtCoder 一直把我当成人机所以交不了。

/*
Code by stringdp100005.

*/

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

using i32 = int32_t;
using i64 = int64_t;
using ui32 = uint32_t;
using ui64 = uint64_t;

int t;

#define string int
string dp[100005];
#undef string

namespace strdp {
	void init() {

	}
	const int N = 2e5, mod = 998244353;
	int n, dp[N + 5], a[N + 5], inv[N + 5];
	int qpow(int x, int y) {
		int res = 1;
		while (y) {
			if (y & 1) res = res * x % mod;
			x = x * x % mod;
			y >>= 1;
		}
		return res;
	}
	vector<int> div[N + 5];
	bool fl[N + 5];
	void main(const int &cas) {
		cin >> n;
		for (int i = 1; i <= N; i++) dp[i] = (dp[i - 1] * 10 + 1) % mod;
		for (int i = 1; i <= N; i++) {
			for (int j = i * 2; j <= N; j += i) {
				div[j].push_back(i);
			}
		}
		for (int i = 1; i <= N; i++) {
			for (int j : div[i]) dp[i] = dp[i] * inv[j] % mod;
			inv[i] = qpow(dp[i], mod - 2);
		}
		int res = 1;
		for (int i = 1; i <= n; i++) {
			int a;
			cin >> a;
			if (!fl[a]) {
				fl[a] = 1;
				res = res * dp[a] % mod;
			}
			for (int j : div[a]) {
				if (!fl[j]) {
					fl[j] = 1;
					res = res * dp[j] % mod;
				}
			}
			cout << res << "\n";
		}
	}
}

// #define multipleTestCases
i32 main() {

#ifdef multipleTestCases
	cin >> t;
#else
	t = 1;
#endif

	for (int i = 1; i <= t; i++) {
		strdp::init();
		strdp::main(i);
		cout << "\n";
	}
	return 0;
}

通过了所有样例。官方题解没看懂,请问我这个做法是和官方题解相同还是错误还是爆标了?

2025/7/21 14:14
加载中...