#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
using namespace std;
void solve(){
int n,k; cin >> n >> k;
int arr[n+1];
map<int, int> num;
map<int, int> ans;
int fork=0;
for(int i=1; i<=n; i++){
cin >> arr[i];
if(arr[i]>k){
num[arr[i]]++;
fork++;
}
}
ans[k]=fork;
for(auto p:num){
int div=p.st-k;
for(int i=1; i*i<=div; i++){
if(i*i==div) ans[p.st]+= num[i];
else if(div%i==0){
ans[p.st]+= num[div/i] + num[i];
}
}
if(k==0) ans[p.st]-=1;
}
for(int i=1; i<=n; i++) cout << ans[arr[i]] << " ";
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
#endif
ll t=1;
//cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1112 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
31 ms |
2128 KB |
Output is correct |
4 |
Correct |
71 ms |
4432 KB |
Output is correct |
5 |
Correct |
571 ms |
17628 KB |
Output is correct |
6 |
Correct |
627 ms |
18348 KB |
Output is correct |
7 |
Correct |
696 ms |
23520 KB |
Output is correct |
8 |
Correct |
710 ms |
23176 KB |
Output is correct |
9 |
Correct |
669 ms |
25024 KB |
Output is correct |
10 |
Correct |
748 ms |
24844 KB |
Output is correct |