#include<bits/stdc++.h> #define FOR(i,s,e) for(int i=(s); i<=(e); i++) #define FORD(i,s,e) for(int i=(s); i>=(e); i--) #define ALL(k) (k).begin(), (k).end() #define e1 first #define e2 second #define mp make_pair using namespace std; using LL=long long; using LD=long double; using PII=pair<int,int>; const int MAXN = 300111; map<int, int> per_city_stamps; int cities_with_k_stamps[MAXN]; vector<int> larger_stamp_no_cities; int ans[MAXN]; int main(){ int n; scanf("%d", &n); FOR(i,1,n){ int a; scanf("%d",&a); if(per_city_stamps.find(a) == per_city_stamps.end()){ per_city_stamps[a] = 1; } else{ per_city_stamps[a]++; } } for(const auto& [city_id, value] : per_city_stamps) { cities_with_k_stamps[value]++; } int threshold = (int)sqrtl(n); FOR(i, threshold, n){ if (cities_with_k_stamps[i] > 0){ larger_stamp_no_cities.push_back(i); } } FOR(k, 1, n){ FOR(j, k, threshold-1){ ans[k] += (j-j%k)*cities_with_k_stamps[j]; } for(auto &j : larger_stamp_no_cities){ ans[k] += (j-j%k) * cities_with_k_stamps[j]; } printf("%d ", ans[k]); } printf("\n"); }
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 | #include<bits/stdc++.h> #define FOR(i,s,e) for(int i=(s); i<=(e); i++) #define FORD(i,s,e) for(int i=(s); i>=(e); i--) #define ALL(k) (k).begin(), (k).end() #define e1 first #define e2 second #define mp make_pair using namespace std; using LL=long long; using LD=long double; using PII=pair<int,int>; const int MAXN = 300111; map<int, int> per_city_stamps; int cities_with_k_stamps[MAXN]; vector<int> larger_stamp_no_cities; int ans[MAXN]; int main(){ int n; scanf("%d", &n); FOR(i,1,n){ int a; scanf("%d",&a); if(per_city_stamps.find(a) == per_city_stamps.end()){ per_city_stamps[a] = 1; } else{ per_city_stamps[a]++; } } for(const auto& [city_id, value] : per_city_stamps) { cities_with_k_stamps[value]++; } int threshold = (int)sqrtl(n); FOR(i, threshold, n){ if (cities_with_k_stamps[i] > 0){ larger_stamp_no_cities.push_back(i); } } FOR(k, 1, n){ FOR(j, k, threshold-1){ ans[k] += (j-j%k)*cities_with_k_stamps[j]; } for(auto &j : larger_stamp_no_cities){ ans[k] += (j-j%k) * cities_with_k_stamps[j]; } printf("%d ", ans[k]); } printf("\n"); } |