#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 1e6+5;
void solve(){
vector<vector<int>> div(N);
for(int i=1;i<N;i++){
for(int j=i;j<N;j+=i) div[i].push_back(j);
}
int n,k;
cin>>n>>k;
vector<int> v(n);
for(auto &i:v) cin>>i;
vector<int> vis(N);
for(auto i : v) vis[i] ++;
vector<int> suffix(N);
suffix[N-1] = vis[N-1];
for(int i=N-1;i>=0;i--) suffix[i] = suffix[i+1] + vis[i];
vector<int> ans(N);
for(int i=0;i<n;i++){
for(auto j : div[v[i]]){
if(v[i]>k && j+k < N && vis[j+k]){
ans[j+k] ++;
}
}
if(v[i] == k) ans[v[i]] += suffix[v[i]+1];
}
if(k == 0){
for(auto &i : ans) i --;
}
for(int i=0;i<n;i++) cout<<ans[v[i]]<<' ';
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
124756 KB |
Output is correct |
2 |
Correct |
184 ms |
124732 KB |
Output is correct |
3 |
Incorrect |
755 ms |
125456 KB |
Output isn't correct |
4 |
Correct |
1203 ms |
126936 KB |
Output is correct |
5 |
Correct |
257 ms |
125332 KB |
Output is correct |
6 |
Correct |
448 ms |
126888 KB |
Output is correct |
7 |
Correct |
263 ms |
125264 KB |
Output is correct |
8 |
Correct |
258 ms |
125260 KB |
Output is correct |
9 |
Correct |
400 ms |
126592 KB |
Output is correct |
10 |
Correct |
368 ms |
126620 KB |
Output is correct |