#include <bits/stdc++.h>
using namespace std;
const int MX=1e6+10;
const int N=3e5+10;
int a[N],cnt[MX],ans[N],bit[MX];
int n,k;
vector<int> getDiv(int x){
vector<int> kq;
if((x==1&&k!=0)||x!=1)kq.push_back(x);
for(int i=2;i*i<=x;++i){
if(x%i==0){
kq.push_back(i);
if(x/i!=i)kq.push_back(x/i);
}
}
return kq;
}
void upd(int i,int val){
for(;i<MX;i+=i&(-i))bit[i]+=val;
}
int get(int i){
int kq=0;
for(;i>0;i-=i&(-i))kq+=bit[i];
return kq;
}
signed main()
{
ios::sync_with_stdio(NULL);
cin.tie(nullptr);
cin>>n>>k;
for(int i=0;i<n;++i)cin>>a[i],cnt[a[i]]++;
for(int i=1;i<MX;++i)if(cnt[i])upd(i,cnt[i]);
for(int i=0;i<n;++i){
if(a[i]<k){ans[i]=0;continue;}
if(k==0&&a[i]==0){ans[i]=n;continue;}
if(a[i]==k){
ans[i]=(n-get(a[i])-cnt[0]);
}else{
auto tmp=getDiv(a[i]-k);
for(int j:tmp){
if(a[i]%j==k&&j!=a[i])ans[i]+=cnt[j];
}
}
}
for(int i=0;i<n;++i)cout<<ans[i]<<' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5836 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
303 ms |
7076 KB |
Output is correct |
4 |
Correct |
895 ms |
9364 KB |
Output is correct |
5 |
Incorrect |
399 ms |
9084 KB |
Output isn't correct |
6 |
Incorrect |
1035 ms |
11376 KB |
Output isn't correct |
7 |
Correct |
407 ms |
9028 KB |
Output is correct |
8 |
Correct |
388 ms |
9084 KB |
Output is correct |
9 |
Correct |
1179 ms |
11280 KB |
Output is correct |
10 |
Correct |
1161 ms |
11428 KB |
Output is correct |