fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  4. typedef long long ll;
  5. //const ll N = 1e5 + 2;
  6. ////const ll OO = LONG_LONG_MAX;
  7. ////const ll mod = 1e9 + 7;
  8. //ll ans[N];
  9. void solve(){
  10. int n; cin>>n;
  11. ll a[n];
  12. for(auto &z: a) cin>>z;
  13. map<ll,int>m;
  14. ll l=0,cnt=0;
  15. ll ans=n;
  16. while(l<n)
  17. {
  18. if(m[a[l]]==0)
  19. {
  20. ++cnt;
  21. m[a[l]]=1;
  22. }
  23. else
  24. {
  25. ans+=(((cnt-1)*cnt)/2);
  26. cnt=1;
  27. m.clear();
  28. m[a[l]]=1;
  29. }
  30. ++l;
  31. }
  32. if(cnt)
  33. {
  34. ans+=(((cnt-1)*cnt)/2);
  35. }
  36. cout<<ans;
  37. }
  38. int main(){
  39. fast;
  40. int t = 1;
  41. //cin >> t;
  42. while (t--){
  43. solve();
  44. cout << "\n";
  45. }
  46. }
  47. // problem:
  48. /*n=8
  49.  * 8c1; 7c2;6c3; 5c4;
  50.  * 8 7 6 5 4 3 2 1
  51.  *
  52.  *
  53.  *
  54.  */
Success #stdin #stdout 0.01s 5384KB
stdin
Standard input is empty
stdout
0