fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. vector<int> v(n);
  8. for (int i = 0; i < n; ++i) {
  9. cin >> v[i];
  10. }
  11. long long l = 0, r = 0;
  12. long long count = 0;
  13. set<int> st;
  14. while (r < n) {
  15. while (st.count(v[r])) {
  16. st.erase(v[l]);
  17. l++;
  18. }
  19. st.insert(v[r]);
  20. count += (r - l + 1);
  21. r++;
  22. }
  23. cout << count;
  24. }
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
5452