#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];
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 |
1562 ms |
122492 KB |
Output is correct |
2 |
Correct |
1571 ms |
121632 KB |
Output is correct |
3 |
Correct |
1608 ms |
123836 KB |
Output is correct |
4 |
Correct |
1768 ms |
126528 KB |
Output is correct |
5 |
Incorrect |
1655 ms |
125304 KB |
Output isn't correct |
6 |
Incorrect |
1730 ms |
128116 KB |
Output isn't correct |
7 |
Correct |
1671 ms |
125432 KB |
Output is correct |
8 |
Correct |
1643 ms |
125304 KB |
Output is correct |
9 |
Correct |
1783 ms |
127988 KB |
Output is correct |
10 |
Correct |
1749 ms |
127864 KB |
Output is correct |