Submission #1265710

#TimeUsernameProblemLanguageResultExecution timeMemory
1265710goulthenSpiderman (COCI20_spiderman)C++20
70 / 70
344 ms21684 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second

const int MAXN = 3e5 + 10;
int a[MAXN], ans[1000001], cnt[1000001];


int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n,k;cin >> n >> k;
	vector<int> v;
	rep(i,1,n) cin >> a[i];
	rep(i,1,n) cnt[a[i]]++;
	rep(i,1,n) v.pb(a[i]);
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()), v.end());


	rep(y,k+1,1000) {
		if (!cnt[y]) continue;
		for (int &val : v) {
			if (val%y==k) ans[val]+=cnt[y];
		}
	}

	rep(i,1,n) {
		if (a[i] > 1000 && a[i] > k) {
			for (int y = k; y <= 1000000; y += a[i]) {
				ans[y]++;
			}
		}
	}

	rep(i,1,n) cout << ans[a[i]]-(k==0) << " \n"[i==n];
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...