# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
633407 | HossamHero7 | Spiderman (COCI20_spiderman) | C++14 | 1203 ms | 126936 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>
using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 1e6+5;
void solve(){
vector<vector<int>> div(N);
for(int i=1;i<N;i++){
for(int j=i;j<N;j+=i) div[i].push_back(j);
}
int n,k;
cin>>n>>k;
vector<int> v(n);
for(auto &i:v) cin>>i;
vector<int> vis(N);
for(auto i : v) vis[i] ++;
vector<int> suffix(N);
suffix[N-1] = vis[N-1];
for(int i=N-1;i>=0;i--) suffix[i] = suffix[i+1] + vis[i];
vector<int> ans(N);
for(int i=0;i<n;i++){
for(auto j : div[v[i]]){
if(v[i]>k && j+k < N && vis[j+k]){
ans[j+k] ++;
}
}
if(v[i] == k) ans[v[i]] += suffix[v[i]+1];
}
if(k == 0){
for(auto &i : ans) i --;
}
for(int i=0;i<n;i++) cout<<ans[v[i]]<<' ';
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |