Submission #633412

#TimeUsernameProblemLanguageResultExecution timeMemory
633412HossamHero7Spiderman (COCI20_spiderman)C++14
70 / 70
1285 ms126840 KiB
#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(k == 0){ for(auto &i : ans) i --; } for(int i=0;i<n;i++){ cout<<(v[i]==k?ans[v[i]]+suffix[v[i]+1]: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 timeMemoryGrader output
Fetching results...