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

int const N = 2e6;
int n, a[N]; 
map<int, int> lst;

int main(){
    scanf("%d", &n);
    for(int i = 0; i<n; ++i){
      scanf("%d", a+i);
      lst[a[i]] = i;
    }
    int an = 0;
    for(int i = 0; i<n; ++i){
        if(lst[a[i]] - i + 1 >= an)an = lst[a[i]] - i + 1;
    }
    printf("%d\n", an);
}
Copy
Good Segment molukhyyeh
GNU G++17
2024 ms
34.1 MB
Time Limit Exceeded