#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-1])-cnt[0]);
}else{
auto tmp=getDiv(a[i]-k);
for(int j:tmp){
if(a[i]%j==k)ans[i]+=cnt[j];
}
}
}
for(int i=0;i<n;++i)cout<<ans[i]<<' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
5948 KB |
Output isn't correct |
2 |
Incorrect |
8 ms |
4300 KB |
Output isn't correct |
3 |
Incorrect |
312 ms |
7204 KB |
Output isn't correct |
4 |
Incorrect |
893 ms |
9316 KB |
Output isn't correct |
5 |
Correct |
348 ms |
9100 KB |
Output is correct |
6 |
Correct |
1018 ms |
11368 KB |
Output is correct |
7 |
Incorrect |
405 ms |
9180 KB |
Output isn't correct |
8 |
Incorrect |
408 ms |
9060 KB |
Output isn't correct |
9 |
Incorrect |
1177 ms |
11264 KB |
Output isn't correct |
10 |
Incorrect |
1150 ms |
11112 KB |
Output isn't correct |