#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MAXN = 1e6 + 5;
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
template<class T> struct BIT{
vector<T> bit;
BIT(){
bit.assign(MAXN, 0);
}
void update(int ind, T delta){
for(; ind < MAXN; ind = ind | (ind + 1)){
bit[ind] += delta;
}
}
T query(int ind){
T sum = 0;
for(; ind >= 0; ind = (ind & (ind + 1)) - 1){
sum += bit[ind];
}
return sum;
}
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
int n, k;
cin >> n >> k;
vi h(n);
map<int, int> m;
BIT<int> bit;
rep(i, n) cin >> h[i], m[h[i]]++, bit.update(h[i], 1);
rep(i, n){
int num = h[i] - k;
int ans = 0;
if(!num) ans += n - bit.query(h[i]);
for(int j = 1; (j * j) <= num; j++){
if(num % j == 0){
if(j != k) ans += m[j];
if(j != (num / j) && (num / j) != k) ans += m[num / j];
}
}
cout << ans << " ";
}
cout << endl;
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
4736 KB |
Output isn't correct |
2 |
Incorrect |
16 ms |
4608 KB |
Output isn't correct |
3 |
Correct |
440 ms |
5600 KB |
Output is correct |
4 |
Incorrect |
1245 ms |
7112 KB |
Output isn't correct |
5 |
Incorrect |
856 ms |
12280 KB |
Output isn't correct |
6 |
Execution timed out |
2099 ms |
12848 KB |
Time limit exceeded |
7 |
Incorrect |
953 ms |
16888 KB |
Output isn't correct |
8 |
Incorrect |
902 ms |
16760 KB |
Output isn't correct |
9 |
Execution timed out |
2021 ms |
17556 KB |
Time limit exceeded |
10 |
Execution timed out |
2089 ms |
17784 KB |
Time limit exceeded |