제출 #1282150

#제출 시각아이디문제언어결과실행 시간메모리
1282150kawhietSpiderman (COCI20_spiderman)C++20
21 / 70
354 ms10272 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) {
            res[i] = (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);
                }
            }
        }
        for (auto f : d) {
            if (f == 1) continue;
            res[i] += cnt[f];
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << ' ';
    }
    cout << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...