Source Code
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N=2e6+5;

int n;
int mp [N];
int main(){
ios_base::sync_with_stdio(false);cin.tie (0);
cin>>n;
int ans=1;
for (int i=1;i <=n;i++){
int a;cin>>a;a+=1000000;
if (mp [a]==0){
mp [a]=i;
continue;
}else {
ans=max (ans,i-mp [a]+1);
}
}
cout <<ans;
}
Copy
Good Segment FEAR
GNU G++17
172 ms
4.7 MB
Accepted