#include <bits/stdc++.h>
#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 1e6+5;
int n,m,q,k;
vector<int> cnt,h;
vector<int> ans;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
void solve() {
cin>>n>>k;
h.resize(n);
ans.resize(n);
cnt.resize(N);
for(int i = 0; i<n; i++) {
cin>>h[i];
}
for(int i = 0; i<n; i++) {
int ind = h[i];
while(ind < N) {
cnt[ind]++;
ind+=h[i];
}
}
for(int i = 0; i<n; i++) {
if(h[i] - k < 0) {
ans[i] = 0;
continue;
}
if(h[i] == k) {
ans[i] = -1;
continue;
}
ans[i] = max(cnt[h[i] - k]-1, 0ll);
}
sort(h.begin(),h.end());
int ind = 0;
while(ind < n && h[ind] <= k) ind++;
int x = n - ind;
for(int i = 0; i<n; i++) {
if(ans[i] == -1) ans[i] = x;
cout<<ans[i]<<" ";
}
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
8284 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
8280 KB |
Output isn't correct |
3 |
Incorrect |
329 ms |
10704 KB |
Output isn't correct |
4 |
Incorrect |
674 ms |
15700 KB |
Output isn't correct |
5 |
Correct |
35 ms |
10504 KB |
Output is correct |
6 |
Correct |
94 ms |
15512 KB |
Output is correct |
7 |
Incorrect |
31 ms |
10760 KB |
Output isn't correct |
8 |
Incorrect |
31 ms |
10580 KB |
Output isn't correct |
9 |
Incorrect |
107 ms |
15612 KB |
Output isn't correct |
10 |
Incorrect |
99 ms |
15532 KB |
Output isn't correct |