fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. const ll lim = 2e5 + 10;
  6. ll n, a[lim], l, r, ans, m[lim];
  7.  
  8. int main() {
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0); cout.tie(0);
  11.  
  12. cin >> n;
  13. for (ll i = 1; i <= n; i++) cin >> a[i];
  14.  
  15. l = 1;
  16. for (ll r = 1; r <= n; r++) {
  17. m[a[r]]++;
  18. while (m[a[r]] > 1 && l < r) {
  19. m[a[l]]--;
  20. l++;
  21. }
  22. ans += r - l + 1;
  23. }
  24.  
  25. cout << ans;
  26. return 0;
  27. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty