Submission #633412

# Submission time Handle Problem Language Result Execution time Memory
633412 2022-08-22T11:04:04 Z HossamHero7 Spiderman (COCI20_spiderman) C++14
70 / 70
1285 ms 126840 KB
#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 time Memory Grader output
1 Correct 155 ms 124840 KB Output is correct
2 Correct 167 ms 124720 KB Output is correct
3 Correct 705 ms 125460 KB Output is correct
4 Correct 1285 ms 126840 KB Output is correct
5 Correct 260 ms 125260 KB Output is correct
6 Correct 469 ms 126784 KB Output is correct
7 Correct 229 ms 125264 KB Output is correct
8 Correct 263 ms 125340 KB Output is correct
9 Correct 423 ms 126692 KB Output is correct
10 Correct 407 ms 126616 KB Output is correct