#include <cstdlib> #include <csignal> #include <csetjmp> #include <cstdarg> #include <typeinfo> #include <typeindex> #include <type_traits> #include <bitset> #include <functional> #include <utility> #include <ctime> #include <chrono> #include <cstddef> #include <initializer_list> #include <tuple> #include <new> #include <memory> #include <scoped_allocator> #include <climits> #include <cfloat> #include <cstdint> #include <cinttypes> #include <limits> #include <exception> #include <stdexcept> #include <cassert> #include <system_error> #include <cerrno> #include <cctype> #include <cwctype> #include <cstring> #include <cwchar> #include <cuchar> #include <string> #include <array> #include <vector> #include <deque> #include <list> #include <forward_list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <stack> #include <queue> #include <algorithm> #include <iterator> #include <cmath> #include <complex> #include <valarray> #include <random> #include <numeric> #include <ratio> #include <cfenv> #include <iosfwd> #include <ios> #include <istream> #include <ostream> #include <iostream> #include <fstream> #include <sstream> #include <strstream> #include <iomanip> #include <streambuf> #include <cstdio> #include <locale> #include <clocale> #include <codecvt> #include <regex> #include <atomic> #include <thread> #include <mutex> #include <future> #include <condition_variable> #include <ciso646> #include <ccomplex> #include <ctgmath> #include <cstdalign> #include <cstdbool> // #include <bits/stdc++.h> using namespace std; int n, a, zliczanie[300005], aktualna_dlugosc; long long wyniki[300005], do_dodania; vector<int> wartosci; int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a; wartosci.push_back(a); } sort(wartosci.begin(), wartosci.end()); aktualna_dlugosc = 1; for (int i = 1; i < n; i++) { if (wartosci[i] != wartosci[i - 1]) { zliczanie[aktualna_dlugosc]++; aktualna_dlugosc = 0; } aktualna_dlugosc++; } zliczanie[aktualna_dlugosc]++; for (int i = 1; i <= n; i++) { if (zliczanie[i] != 0) { for (int j = 1; j <= i; j++) { do_dodania = i / j; do_dodania *= j; wyniki[j] += (long long)(zliczanie[i]) * do_dodania; } } } for (int i = 1; i <= n; i++) cout << wyniki[i] << " "; }
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #include <cstdlib> #include <csignal> #include <csetjmp> #include <cstdarg> #include <typeinfo> #include <typeindex> #include <type_traits> #include <bitset> #include <functional> #include <utility> #include <ctime> #include <chrono> #include <cstddef> #include <initializer_list> #include <tuple> #include <new> #include <memory> #include <scoped_allocator> #include <climits> #include <cfloat> #include <cstdint> #include <cinttypes> #include <limits> #include <exception> #include <stdexcept> #include <cassert> #include <system_error> #include <cerrno> #include <cctype> #include <cwctype> #include <cstring> #include <cwchar> #include <cuchar> #include <string> #include <array> #include <vector> #include <deque> #include <list> #include <forward_list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <stack> #include <queue> #include <algorithm> #include <iterator> #include <cmath> #include <complex> #include <valarray> #include <random> #include <numeric> #include <ratio> #include <cfenv> #include <iosfwd> #include <ios> #include <istream> #include <ostream> #include <iostream> #include <fstream> #include <sstream> #include <strstream> #include <iomanip> #include <streambuf> #include <cstdio> #include <locale> #include <clocale> #include <codecvt> #include <regex> #include <atomic> #include <thread> #include <mutex> #include <future> #include <condition_variable> #include <ciso646> #include <ccomplex> #include <ctgmath> #include <cstdalign> #include <cstdbool> // #include <bits/stdc++.h> using namespace std; int n, a, zliczanie[300005], aktualna_dlugosc; long long wyniki[300005], do_dodania; vector<int> wartosci; int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a; wartosci.push_back(a); } sort(wartosci.begin(), wartosci.end()); aktualna_dlugosc = 1; for (int i = 1; i < n; i++) { if (wartosci[i] != wartosci[i - 1]) { zliczanie[aktualna_dlugosc]++; aktualna_dlugosc = 0; } aktualna_dlugosc++; } zliczanie[aktualna_dlugosc]++; for (int i = 1; i <= n; i++) { if (zliczanie[i] != 0) { for (int j = 1; j <= i; j++) { do_dodania = i / j; do_dodania *= j; wyniki[j] += (long long)(zliczanie[i]) * do_dodania; } } } for (int i = 1; i <= n; i++) cout << wyniki[i] << " "; } |