Submission #844355

# Submission time Handle Problem Language Result Execution time Memory
844355 2023-09-05T12:36:45 Z vjudge1 Spiderman (COCI20_spiderman) C++17
56 / 70
145 ms 27216 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 1e6 + 5;

vector<ll> A, A2;
ll divCnt[MAXN], newCnt[MAXN];
map<ll,ll> mp;
int main() {
	fast
	ll N, K;
	cin >> N >> K;

	A = vector<ll>(N+1);
	A2 = vector<ll>(N+1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		mp[A[i]]++;
		A2[i] = A[i];
	}
	sort(A2.begin(), A2.end());

	for (int i = 1; i <= N; i++)
		divCnt[A[i]]++;

	for (int i = K+1; i < MAXN; i++) {
		if (divCnt[i] == 0)
			continue;
		for (int j = i; j < MAXN; j+=i) {
			newCnt[j] += divCnt[i];
		}
	}

	for (int i = 1; i <= N; i++) {
		if (A[i] == K) {
			int Q = upper_bound(A2.begin(), A2.end(), A[i]) - A2.begin();
			cout << N - Q + 1 << " ";
		} else if (A[i] < K)
			cout << "0 ";
		else {
			ll ans = newCnt[A[i] - K];
			cout << ans << " ";
		}
	}
	cout << "\n"; 
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 15452 KB Output is correct
2 Correct 6 ms 15300 KB Output is correct
3 Correct 27 ms 17244 KB Output is correct
4 Correct 67 ms 21144 KB Output is correct
5 Incorrect 64 ms 24144 KB Output isn't correct
6 Incorrect 131 ms 27216 KB Output isn't correct
7 Correct 59 ms 24152 KB Output is correct
8 Correct 68 ms 23932 KB Output is correct
9 Correct 130 ms 27112 KB Output is correct
10 Correct 145 ms 27124 KB Output is correct