#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN=300001;
const ll MAXK=1000001;
const ll INF = 1e9;
const ll MOD = 1e9+7;
int A[MAXN];
int B[MAXK];
int res[MAXN];
int dp[MAXK];
int N,K,a;
vi V[MAXK];
int calc(int x){
if(dp[x]!=-1)return dp[x];
dp[x]=0;
for(auto i:V[x])dp[x]+=B[i];
if(K==0)--dp[x];
return dp[x];
}
int main(){
for(int i=1;i<=MAXK;++i)for(int j=i;j<=MAXK;j+=i){
V[j].pb(i);
}
cin>>N>>K;
memset(res,-1,sizeof(res));
memset(dp,-1,sizeof(dp));
int x=0;
for(int i=1;i<=N;++i){
cin>>A[i];
if(A[i]<K)res[i]=0;
if (A[i]>K){
++x;
B[A[i]]++;
}
}
for(int i=1;i<=N;++i)if(A[i]==K){
res[i]=x;
}
for(int i=1;i<=N;++i)if(res[i]==-1){
res[i]=calc(A[i]-K);
}
for(int i=1;i<=N;++i)cout<<res[i]<<' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1542 ms |
122488 KB |
Output is correct |
2 |
Correct |
1554 ms |
121692 KB |
Output is correct |
3 |
Correct |
1670 ms |
123968 KB |
Output is correct |
4 |
Correct |
1704 ms |
126400 KB |
Output is correct |
5 |
Correct |
1612 ms |
125440 KB |
Output is correct |
6 |
Correct |
1727 ms |
127988 KB |
Output is correct |
7 |
Correct |
1671 ms |
125480 KB |
Output is correct |
8 |
Correct |
1706 ms |
125516 KB |
Output is correct |
9 |
Correct |
1764 ms |
128120 KB |
Output is correct |
10 |
Correct |
1769 ms |
128088 KB |
Output is correct |