Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.52 KB | None | 0 0
  1. /*
  2.  
  3. Sviatoslav Bidzilia 2019
  4. CF: anakib1
  5.  
  6. */
  7.  
  8. #include <iostream>
  9. #include <cmath>
  10. #include <algorithm>
  11. #include <stdio.h>
  12. #include <cstring>
  13. #include <string>
  14. #include <cstdlib>
  15. #include <vector>
  16. #include <bitset>
  17. #include <map>
  18. #include <chrono>
  19. #include <unordered_set>
  20. #include <unordered_map>
  21. #include <numeric>
  22. #include <queue>
  23. #include <ctime>
  24. #include <stack>
  25. #include <set>
  26. #include <list>
  27. #include <deque>
  28. #include <iomanip>
  29. #include <sstream>
  30. #include <fstream>
  31. #include <stdarg.h>
  32. #include <utility>
  33.  
  34. using namespace std;
  35.  
  36. #define pb push_back
  37. #define mp make_pair
  38. #define ll long long
  39. #define ull unisgned long long
  40. #define ld long double
  41. #define all(a) a.begin(), a.end()
  42. #define SORT(a) sort(all(a))
  43. #define pii pair<int, int>
  44. #define tii triple<int, int, int>
  45. #define e 1e-7
  46. #define PI acos(-1)
  47. #define inf 1e17
  48. #define vi vector<int>
  49. #define F first
  50. #define S second
  51. #define rng(x) for(int _ = 0; _ < (x); _++)
  52. #define rngi(i, x) for(int i = 0; i < (x); i++)
  53. #define rngsi(s, i, x) for(int i = (s); i <(x); i++)
  54. #define int long long
  55.  
  56. template<typename A, typename B, typename C>
  57. struct triple
  58. {
  59.     A X;
  60.     B Y;
  61.     C Z;
  62.     triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
  63. };
  64. template<typename A, typename B, typename C>
  65. triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
  66. {
  67.     return triple<A, B, C>(a, b, c);
  68. }
  69. template<typename A, typename B, typename C>
  70. bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
  71. {
  72.     if (a.X != b.X)
  73.         return a.X < b.X;
  74.     if (a.Y != b.Y)
  75.         return a.Y < b.Y;
  76.     return a.Z < b.Z;
  77. }
  78. template<typename T, typename SS>
  79. ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
  80. {
  81.     ofs << "( " << p.F << " , " << p.S << " )";
  82.     return ofs;
  83. }
  84. template<typename T>
  85. void print(T a)
  86. {
  87.     for (auto i : a)
  88.         cout << i << ' ';
  89.     cout << '\n';
  90. }
  91. template<typename T>
  92. T max(T a, T b, T c)
  93. {
  94.     return max(a, max(b, c));
  95. }
  96. template<typename T>
  97. T min(T a, T b, T c)
  98. {
  99.     return min(a, min(b, c));
  100. }
  101. struct custom_hash
  102. {
  103.     static uint64_t splitmix64(uint64_t x)
  104.     {
  105.         x += 0x9e3779b97f4a7c15;
  106.         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  107.         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  108.         return x ^ (x >> 31);
  109.     }
  110.  
  111.     size_t operator()(uint64_t x) const
  112.     {
  113.         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  114.         return splitmix64(x + FIXED_RANDOM);
  115.     }
  116. };
  117. signed main()
  118. {
  119.     //freopen(".in", "r", stdin);
  120.     //freopen(".out", "w", stdout);
  121.     srand(time(NULL));
  122.     cin.tie(0);
  123.     cout.tie(0);
  124.     ios_base::sync_with_stdio(false);
  125.     int n;
  126.     cin >> n;
  127.     vi a(n);
  128.     for (auto& i : a)
  129.         cin >> i;
  130.     unordered_map<int, int > last;
  131.     vi prv(n, -1);
  132.     rngi(i, n)
  133.     {
  134.         if (last.count(a[i]))
  135.             prv[i] = last[a[i]];
  136.         last[a[i]] = i;
  137.     }
  138.     vi addadd(n + 2);
  139.     vi ansadd(n + 2);
  140.     vi ans(n + 1);
  141.     for (int i = 0; i < n; i++)
  142.     {
  143.         int dl = i - prv[i];
  144.         int dr = n - i;
  145.         int d = min(dl, dr);
  146.         int dm = max(dl, dr);
  147.         /*for (int j = 1; j < d; j++)
  148.             ansadd[j] ++;*/
  149.  
  150.         addadd[1] ++;
  151.         addadd[d] --;
  152.         ansadd[d] -= (d - 1);
  153.        
  154.         /*for (int x = d; x < d + dm; x++)
  155.             ans[x]+=d;*/
  156.         ansadd[d] += d;
  157.         ansadd[d + dm] -= d;
  158.    
  159.         /*for (int j = dm + 1; j < d + dm; j++)
  160.             ansadd[j]--;*/
  161.         addadd[dm + 1]--;
  162.         addadd[d + dm]++;
  163.         ansadd[d + dm] += (d - 1);
  164.             //ans[j] += d + dm - j;
  165.     }
  166.     //ans[1] = n;
  167.     int q = 0;
  168.     int p = 0;
  169.     for (int i = 1; i <= n; i++)
  170.     {
  171.         q += addadd[i];
  172.         ansadd[i] += q;
  173.         p += ansadd[i];
  174.         ans[i] += p;
  175.     }
  176.     for (int i = 1; i <= n; i++)
  177.         cout << ans[i] << ' ';
  178. }
  179. /*
  180. 5
  181. 1 3 2 1 2
  182. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement