Advertisement
Josif_tepe

Untitled

Mar 16th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <fstream>
  6. #include <map>
  7. #include <stack>
  8. using namespace std;
  9. typedef long long ll;
  10. const int INF = 1e9;
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(false);
  15. //    ifstream cin("in.txt");
  16.     int n;
  17.     cin >> n;
  18.     vector<int> v(n);
  19.     for(int i = 0; i < n; i++) {
  20.         cin >> v[i];
  21.     }
  22.     map<int, int> cnt;
  23.     int L = 0, R = 0;
  24.     int current_length = 0;
  25.     int ans = 0;
  26.     while(R < n) {
  27.         if(cnt.find(v[R]) == cnt.end() or cnt[v[R]] == 0) {
  28.             cnt[v[R]] += 1;
  29.             current_length += 1;
  30.             ans = max(ans, current_length);
  31.             R += 1;
  32.         }
  33.         else {
  34.             current_length -= 1;
  35.             cnt[v[L]] -= 1;
  36.             L += 1;
  37.         }
  38.     }
  39.     cout << ans << endl;
  40.     return 0;
  41. }
  42. /*
  43.  mapa<int, int> m;
  44.  1 2 1 3 2 i7 4 2j
  45.  */
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement