#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define debug(x) cerr << '[' << (#x) << "] = " << x << '\n';
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
const int maxn = 1e6 + 6;
vector<int>divisor[maxn];
void sieve() {
for(int i=1; i<maxn; ++i) {
for(int j=i; j<maxn; j+=i)
divisor[j].push_back(i);
}
}
void PlayGround() {
int n; cin >> n;
int k; cin >> k;
vector<int>freq(maxn), ans(maxn);
vector<int>h(n);
int big = 0;
for(int i=0; i<n; ++i) {
cin >> h[i];
freq[h[i]]++;
big += h[i]>k;
}
for(int i=k+1; i<maxn; ++i) {
for(int j=i; j+k<maxn; j+=i) {
ans[j+k] += freq[i] - (j+k==i);
}
}
// int seen = 0;
// for(int i=1; i<maxn; ++i) {
// seen += freq[i];
// if(freq[i]==0) continue;
// if(i==k) {
// ans[i] += n - seen;
// } else if(i > k) {
// int x = i - k;
// for(auto d : divisor[x])
// if(i % d == k) ans[i] += freq[d];
// if(x==i) --ans[i];
// }
// }
for(int i=0; i<n; ++i) {
cout << ans[h[i]] + (h[i]==k ? big : 0) << ' ';
}
cout << '\n';
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
sieve();
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1871 ms |
122780 KB |
Output is correct |
2 |
Correct |
1958 ms |
122788 KB |
Output is correct |
3 |
Correct |
1897 ms |
123496 KB |
Output is correct |
4 |
Correct |
1994 ms |
124808 KB |
Output is correct |
5 |
Correct |
1888 ms |
123456 KB |
Output is correct |
6 |
Correct |
1945 ms |
124900 KB |
Output is correct |
7 |
Correct |
1833 ms |
123336 KB |
Output is correct |
8 |
Correct |
1873 ms |
123320 KB |
Output is correct |
9 |
Correct |
1912 ms |
124724 KB |
Output is correct |
10 |
Correct |
1877 ms |
124716 KB |
Output is correct |