Submission #1304239

#TimeUsernameProblemLanguageResultExecution timeMemory
1304239edgrigSpiderman (COCI20_spiderman)C++20
70 / 70
1012 ms45764 KiB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <stdint.h>
#include <string>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpi = vector<pi>;
using vpll = vector<pll>;
using mii = map<int, int>;
using mll = map<ll, ll>;

#define ff first
#define ss second
//#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

void fastio() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	return;
}

ull gcd(ull a, ull b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

ull lcm(ull a, ull b) {
	return a / gcd(a, b) * b;
}

string dec_to_bin(ll a) {
	string s = "";
	for (ll i = a; i > 0; ) {
		ll k = i % 2;
		i /= 2;
		char c = k + 48;
		s += c;
	}
	if (a == 0) {
		s = "0";
	}
	reverse(s.begin(), s.end());
	return s;
}

ll bin_to_dec(string s) {
	ll num = 0;
	for (int i = 0; i < s.size(); i++) {
		num *= 2ll;
		num += (s[i] - '0');
	}
	return num;
}

bool isPrime(ll a) {
	if (a == 1) {
		return false;
	}
	for (ll i = 2; i * i <= a; i++) {
		if (a % i == 0) {
			return false;
		}
	}
	return true;
}

int dig_sum(ll a) {
	int sum = 0;
	while (a) {
		sum += int(a % 10);
		a /= 10;
	}
	return sum;
}

ll binpow(ll a, int b) {
	ll ans = 1;
	while (b) {
		if ((b & 1) == 1) {
			ans *= a;
		}
		b >>= 1;
		a *= a;
	}
	return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod) {
	ll ans = 1;
	while (b) {
		if ((b & 1) == 1) {
			ans *= a;
			ans %= mod;
		}
		b >>= 1;
		a *= a;
		a %= mod;
	}
	return ans;
}

ll factorial(int a) {
	ll ans = 1;
	for (int i = 2; i <= a; i++) {
		ans *= ll(i);
	}
	return ans;
}

ll factorial_by_mod(int a, ll mod) {
	ll ans = 1;
	for (int i = 2; i <= a; i++) {
		ans *= ll(i);
		ans %= mod;
	}
	return ans;
}

string lex_small(string s, string t)
{
	if (s < t) return s;
	return t;
}

vector<int> find_divisors(int a)
{
	vector<int> ret;
	int sq = sqrt(a);
	for (int i = 1; i <= sq; i++)
	{
		if (a % i == 0)
		{
			ret.pb(i);
			if (i * i != a)
			{
				ret.pb(a / i);
			}
		}
	}
	return ret;
}

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> h(n), h1(n);
	map<int, int> mp;
	vector<vector<int> > div(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		mp[h[i]]++;
	}
	h1 = h;
	sort(h1.begin(), h1.end());
	for (int i = 0; i < n; i++)
	{
		if (h[i] == k) div[i].pb(-2);
		else if (h[i] < k) div[i].pb(-1);
		else div[i] = find_divisors(h[i] - k);
	}
	vector<int> ans(n);
	for (int i = 0; i < n; i++)
	{
		if (div[i][0] == -1) ans[i] = 0;
		else if (div[i][0] == -2)
		{
			int ind = upper_bound(h1.begin(), h1.end(), h[i]) - h1.begin();
			ans[i] = n - ind;
		}
		else
		{
			for (auto v : div[i])
			{
				if (v > k || !k)
					ans[i] += mp[v];
				if (v == h[i]) ans[i]--;
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << " ";
	}
	cout << "\n";
}

int main()
{
	int test_cases = 1;
	//cin >> test_cases;

	while (test_cases--)
	{
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...