Source Code
// 7al.cpp
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
int n, ans;
vector <int> v[1000001];
int main(){
	scanf("%d", &n);
	for(int i = 0, x; i < n; ++i){
		scanf("%d", &x);
		v[x + 500000].push_back(i);
	}
	for(int i = 0; i < 1000001; ++i){
		if(v[i].size()){
			ans = max(ans, v[i][v[i].size() - 1] - v[i][0] + 1);
		}
	}
	printf("%d", ans);
	return 0;
}
Copy
Good Segment Light
GNU G++17
358 ms
55.0 MB
Accepted