Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end() 

int const N = 1e6+1;
int n, a[N]; 
map<int, bool> vs; 
map<int, int> f;

int main(){
    scanf("%d", &n);
    int an = 1;
    for(int i = 1; i<=n; ++i){
      scanf("%d", a+i);
      if(f[a[i]]){
           an = max(an, i - f[a[i]] + 1);
      }
      else f[a[i]] = i;
    }
    printf("%d\n", an);
}
Copy
Good Segment molukhyyeh
GNU G++17
1393 ms
51.6 MB
Accepted