1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>

using namespace std;

int update(int i, int p, int q, int l, int r, int d, vector<int> &T)
{
    if(l<=p && q<=r) return T[i] = T[i]+d;
    if(p>r || q<l) return T[i];

    int c = (p+q)/2;
    T[2*i] += T[i];
    T[2*i+1] += T[i];
    T[i] = 0;

    update(2*i, p, c, l, r, d, T);
    update(2*i+1, c+1, q, l, r, d, T);

    return 0;
}

int query(int i, int p, int q, int a, vector<int> &T)
{
    if(p==q && p==a) return T[i];
    
    int c = (p+q)/2;
    T[2*i] += T[i];
    T[2*i+1] += T[i];
    T[i] = 0;

    if(a <= c) return query(2*i, p, c, a, T);
    return query(2*i+1, c+1, q, a, T);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    unordered_map<int, int> M;
    for(int i=0; i<n; i++)
    {
        int a;
        cin >> a;
        M[a]++;
    }

    vector<int> A;
    for(auto it:M) A.push_back(it.second);
    
    int x = ceil(log2(n));
    vector<int> T(1<<(x+1));
    int y = 1<<x;

    for(auto it:A)
    {
        for(int i=0; i<it; i++) T[y+i] += it%(i+1);
        T[1] = update(1, y, T.size()-1, y+it, T.size()-1, it, T);

        /*cerr << it << "\n";
        for(int i=1; i<T.size(); i++) cerr << i << " " << T[i] << "\n";
        cerr << "\n";*/
    }

    for(int i=0; i<n; i++) cout << n - query(1, y, T.size()-1, y+i, T) << " ";
    cout << "\n";
}