Submission #844721

# Submission time Handle Problem Language Result Execution time Memory
844721 2023-09-05T18:12:47 Z vjudge1 Spiderman (COCI20_spiderman) C++17
70 / 70
693 ms 13904 KB
#include <bits/stdc++.h>
#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)



using namespace std;

const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 1e6+5;
int n,m,q,k;
vector<int> cnt,h;
vector<int> ans;
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

}

void solve() {
    cin>>n>>k;
    h.resize(n);
    ans.resize(n);
    cnt.resize(N,0);
    for(int i = 0; i<n; i++) {
        cin>>h[i];
    }
    for(int i = 0; i<n; i++) {
        if(h[i] <= k) continue;
        int ind = h[i];
        while(ind < N) {
            cnt[ind]++;
            ind+=h[i];
        }
    }
    for(int i = 0; i<n; i++) {
        if(h[i] - k < 0) {
            ans[i] = 0;
            continue;
        } 
        if(h[i] == k) {
            ans[i] = -1;   
            continue;
        }
        ans[i] = cnt[h[i] - k];
    }
    sort(h.begin(),h.end());
    int ind = 0;
    while(ind < n && h[ind] <= k) ind++;
    int x = n - ind;
    for(int i = 0; i<n; i++) {
        if(k==0) ans[i]--;
        if(ans[i] == -1) ans[i] = x;
        cout<<ans[i]<<" ";
    }
}
 
signed main() {
    
    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8280 KB Output is correct
2 Correct 9 ms 8280 KB Output is correct
3 Correct 317 ms 10100 KB Output is correct
4 Correct 693 ms 13904 KB Output is correct
5 Correct 34 ms 10064 KB Output is correct
6 Correct 98 ms 13648 KB Output is correct
7 Correct 41 ms 10112 KB Output is correct
8 Correct 28 ms 10328 KB Output is correct
9 Correct 93 ms 13648 KB Output is correct
10 Correct 86 ms 13648 KB Output is correct