Josif_tepe

Untitled

Dec 11th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6. const int INF = 2e9;
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     int n;
  10.     cin >> n;
  11.    
  12.     vector<int> v(n);
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> v[i];
  15.     }
  16.    
  17.     map<int, int> cnt;
  18.     int i = 0, j = 0;
  19.     int res = 0;
  20.     while(j < n) {
  21.         if(cnt[v[j]] == 0) {
  22.             cnt[v[j]]++;
  23.             res = max(res, j - i + 1);
  24.             j++;
  25.         }
  26.         else {
  27.             cnt[v[i]]--;
  28.             i++;
  29.         }
  30.     }
  31.    
  32.     cout << res << endl;
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment