Advertisement
Galebickosikasa

Untitled

Oct 20th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. //#pragma GCC optimize ("unroll_loops,fast_math")
  2. //#pragma GCC target ("avx,avx2")
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <cmath>
  7. #include <map>
  8. #include <set>
  9. #include <unordered_map>
  10. #include <unordered_set>
  11. #include <random>
  12. #include <algorithm>
  13.  
  14. #define ll long long
  15. #define sz(v) (int)v.size()
  16. #define forn(i, n) for (int i = 0; i < n; ++i)
  17. #define forln(i, l, n) for (int i = l; i < n; ++i)
  18. #define cinv(v) for (auto& x: v) cin >> x
  19. #define fr first
  20. #define se second
  21. #define all(v) v.begin(), v.end()
  22. #define pb push_back
  23. #define pii pair<int, int>
  24. #define pll pair<ld, ld>
  25. #define ld long double
  26. #define hm unordered_map
  27.  
  28. using namespace std;
  29.  
  30. const ll inf = (ll)2e9;
  31. const ll N = 5001;
  32.  
  33. random_device rd;
  34. mt19937 rnd(rd());
  35.  
  36. ll kek (vector<int>& goo, int d) {
  37. ll res = 0;
  38. ll ans = 0;
  39. int cnt[N];
  40. for (auto& x: cnt) x = 0;
  41. forn (i, d) {
  42. if (cnt[goo[i]] == 0) ++res;
  43. ++cnt[goo[i]];
  44. }
  45. ans += res;
  46. forln (i, 1, sz (goo)) {
  47. if (i + d - 1 >= sz (goo)) break;
  48. int x = goo[i - 1];
  49. if (cnt[x] == 1) --res;
  50. --cnt[x];
  51. if (cnt[goo[i + d - 1]] == 0) ++res;
  52. ++cnt[goo[i + d - 1]];
  53. ans += res;
  54. }
  55. return ans;
  56. }
  57.  
  58. int main () {
  59. ios_base::sync_with_stdio (false);
  60. cout.tie(nullptr);
  61. cin.tie(nullptr);
  62. int n;
  63. cin >> n;
  64. vector<int> goo (n);
  65. cinv (goo);
  66. auto moo = goo;
  67. sort (all (moo));
  68. moo.resize (unique(all(moo)) - moo.begin());
  69. for (auto& x: goo) x = lower_bound(all (moo), x) - moo.begin();
  70. vector<ll> ans (n);
  71. forln (i, 1, n + 1) {
  72. ans[i - 1] = kek(goo, i);
  73. }
  74. for (auto& x: ans) cout << x << ' ';
  75.  
  76.  
  77.  
  78.  
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement