Submission #1282172

#TimeUsernameProblemLanguageResultExecution timeMemory
1282172kawhietSpiderman (COCI20_spiderman)C++20
70 / 70
360 ms10276 KiB
#include <bits/stdc++.h>
using namespace std;

constexpr int N = 1e6 + 1;

int cnt[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        cnt[h[i]]++;
    }
    int greater = 0;
    for (int i = 0; i < n; i++) {
        greater += h[i] > k;
    }
    vector<int> res(N);
    for (int i = 0; i < n; i++) {
        if (h[i] <= k) {
            cout << (h[i] == k ? greater : 0) << ' ';
            continue;
        }
        int x = h[i] - k;
        vector<int> d;
        for (int f = 1; f * f <= x; f++) {
            if (x % f == 0) {
                d.push_back(f);
                if (f * f != x) {
                    d.push_back(x / f);
                }
            }
        }
        int res = 0;
        for (auto f : d) {
            if (h[i] % f == k) {
                res += cnt[f];
            }
        }
        cout << res - int(k == 0) << ' ';
    }
    cout << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...