#include <bits/stdc++.h>
#define lg(a) (31 - __builtin_clz((a)))
#define endl ("\n")
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define vi vector<int>
#define all(aa) aa.begin(), aa.end()
#define forn(i, n) for(int i=0;i<n;i++)
#define trav(e, x) for(auto& e:x)
#define until(n, v) (int) (lower_bound(v.begin(), v.end(), n)-v.begin()) //# of elements < n
#define after(n, v) (int) (v.end()-upper_bound(v.begin(), v.end(), n)) //# of elements > n
#define sameas(n, v) (int) (upper_bound(v.begin(), v.end(), n) - lower_bound(v.begin(), v.end(), n)) //# of elements ==n
typedef long long ll;
using namespace std;
/*
*/
vector<int> genfac(vector<pair<int, int>> pfact, int mpindex, vector<int> factors){
if (mpindex == pfact.size()-1) return factors;
mpindex++;
int n = factors.size();
int exp = 1;
for(int i=1;i<=pfact[mpindex].second;i++){
exp*=pfact[mpindex].first;
for(int j=0;j<n;j++){
factors.pb(exp * factors[j]);
}
}
return genfac(pfact, mpindex, factors);
}
vector<int> factorize(int n){
vector<pair<int, int>> pfact;
for(int i=2;i<=n;i++){
if(n%i==0){
n/=i;
pfact.pb(mp(i, 1));
}
while(n%i==0){
pfact.back().second++;
n/=i;
}
}
vector<int> factors; factors.pb(1);
factors = genfac(pfact, -1, factors);
return factors;
}
void solve(){
int n, k; cin>>n>>k;
vi v(n), cnt(1e6+5, 0);
for(auto &e:v){
cin>>e; cnt[e]++;
}
vi sorted(v);
sort(all(sorted));
for(int i=0; i<n;i++){
int ans = 0;
if(v[i] >= k){
if(v[i] == k){
ans = after(k, sorted);
}
vi p(factorize(abs(v[i]-k)));
for(auto e : p){
if(e > k) ans+= cnt[e] - (e==v[i]);
}
}
cout<<ans<<' ';
}
}
int main(){
solve();
}
Compilation message
spiderman.cpp: In function 'std::vector<int> genfac(std::vector<std::pair<int, int> >, int, std::vector<int>)':
spiderman.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if (mpindex == pfact.size()-1) return factors;
| ~~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
4436 KB |
Output is correct |
2 |
Correct |
267 ms |
4184 KB |
Output is correct |
3 |
Execution timed out |
2049 ms |
5200 KB |
Time limit exceeded |
4 |
Execution timed out |
2023 ms |
6804 KB |
Time limit exceeded |
5 |
Execution timed out |
2053 ms |
5420 KB |
Time limit exceeded |
6 |
Execution timed out |
2051 ms |
6964 KB |
Time limit exceeded |
7 |
Execution timed out |
2029 ms |
5208 KB |
Time limit exceeded |
8 |
Execution timed out |
2041 ms |
4944 KB |
Time limit exceeded |
9 |
Execution timed out |
2056 ms |
6784 KB |
Time limit exceeded |
10 |
Execution timed out |
2039 ms |
6700 KB |
Time limit exceeded |