Salvens

Untitled

Jan 11th, 2024
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  8.  
  9. //#include <ext/pb_ds/assoc_container.hpp>
  10. //using namespace __gnu_pbds;
  11. //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  12. std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
  13.  
  14. const int INF = 1e18 + 7;
  15. const double EPS = 1e-10;
  16. const int MOD = 1e9 + 7;
  17. const int MAXN = 3e6 + 100;
  18.  
  19. inline void solve() {
  20.     int n;
  21.     cin >> n;
  22.     vector<int> a(n + 1);
  23.     for (int i = 1; i <= n; ++i) {
  24.         cin >> a[i];
  25.     }
  26.  
  27.     map<int, int> last;
  28.     vector<int> b;
  29.     for (int i = 1; i <= n; ++i) {
  30.         b.emplace_back(i - last[a[i]] - 1);
  31.         last[a[i]] = i;
  32.     }
  33.     for (auto [x, y]:  last) {
  34.         b.emplace_back(n - y);
  35.     }
  36.  
  37.     sort(b.begin(), b.end());
  38.     vector<int> suff(b.size() + 1, 0);
  39.     for (int i = b.size() - 1; i >= 0; --i) {
  40.         suff[i] = suff[i + 1] + b[i];
  41.     }
  42.  
  43.     for (int len = 1; len <= n; ++len) {
  44.         int pos = upper_bound(b.begin(), b.end(), len - 1) - b.begin();
  45.         cout << suff[pos] - ((int)b.size() - pos) * (len - 1) << ' ';
  46.     }
  47. }
  48.  
  49.  
  50. int32_t main() {
  51.     IOS;
  52.     clock_t tStart = clock();
  53.  
  54.     int tt = 1;
  55. //    cin >> tt;
  56.     while (tt --> 0) {
  57.         solve();
  58.     }
  59. //    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment