# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844354 | vjudge1 | Spiderman (COCI20_spiderman) | C++17 | 1276 ms | 24140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;
const int inf = 2e18 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int32_t main(){
//freopen("in.txt","r", stdin);
int n, k;
cin>>n>>k;
vector<pair<int, int> > h(n);
for(int i = 0; i < n; i++){
cin>>h[i].first;
h[i].second = i;
}
sort(h.begin(), h.end());
vector<int> ans(n);
map<int, int> mp;
if(k > 0){
for(int i = 0; i < n; i++){
if(h[i].first < k){
ans[h[i].second] = 0;
}
else if(h[i].first == k){
ans[h[i].second] = (n - i - 1);
}
else{
int x = h[i].first - k, cnt = 0;
for(int j = 1; j * j <= x; j++){
if(x%j == 0){
if(j > k) cnt += mp[j];
if(x/j != j && x/j > k) cnt += mp[x/j];
//if(x == 6) cout<<j<<" "<<x/j<<" "<<mp[j]<<" "<<mp[x/j]<<" "<<cnt<<endl;
}
}
ans[h[i].second] = cnt;
}
mp[h[i].first]++;
}
}
else{
for(int i = 0; i < n; i++) mp[h[i].first]++;
for(int i = 0; i < n; i++){
int x = h[i].first - k, cnt = 0;
for(int j = 1; j * j <= x; j++){
if(x%j == 0){
if(j > k) cnt += mp[j];
if(x/j != j && x/j > k) cnt += mp[x/j];
//if(x == 6) cout<<j<<" "<<x/j<<" "<<mp[j]<<" "<<mp[x/j]<<" "<<cnt<<endl;
}
}
ans[h[i].second] = cnt;
}
}
for(int i = 0; i < n; i++){
cout<<ans[i]<<" ";
}
cout<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |