Submission #1316445

#TimeUsernameProblemLanguageResultExecution timeMemory
1316445ninstroyerSpiderman (COCI20_spiderman)C++20
70 / 70
166 ms11616 KiB
#include<bits/stdc++.h>
using namespace std;

const int nx = 3e5+5, hx = 1e6+5;

int n, k, actual[nx], cnt[hx], has[hx];
vector<int> arr;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k;
    for(int i = 1; i <= n; i++) cin>>actual[i], has[actual[i]]++, arr.push_back(actual[i]);
    sort(arr.begin(),arr.end());
    arr.erase(unique(arr.begin(),arr.end()),arr.end());
    int m = arr.size();
    for(int i = 0; i < m; i++)
    {
        if(arr[i]==k) for(int j = i+1; j < m; j++) cnt[arr[i]] += has[arr[j]];
        if(arr[i]<=k) continue;
        int x = arr[i]-k;
        for(int j = 1; j*j <= x; j++)
        {
            if((x%j))continue;
            if(j>k)cnt[arr[i]] += has[j];
            int other = x/j;
            if(other==j || other <= k) continue;
            else cnt[arr[i]] += has[other];
        }
        if(k==0) cnt[arr[i]]--;
    }
    for(int i = 1; i <= n; i++) cout<<cnt[actual[i]]<<" ";
}
#Verdict Execution timeMemoryGrader output
Fetching results...