Source Code
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define md ((st + nd) >> 1)
#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))
const int N = 1000006;
int fst[N];

int main() {
	int sh = N >> 1;
	int n;
	scanf("%d", &n);
	int res = 1;
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		if (fst[x+sh]) {
			res = max(res, i - fst[x+sh] + 1);
		} else {
			fst[x+sh] = i;
		}
	}
	printf("%d", res);
	return 0;
}
Copy
Good Segment aboAdnan
GNU G++17
239 ms
4.6 MB
Accepted