You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 100010;
|
|
|
|
|
int a[N]; // 原数组
|
|
|
|
|
int b[N]; // 记个数的桶
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
|
|
|
for (int i = 1, j = 1; i <= n; i++) {
|
|
|
|
|
b[a[i]]++; // a[i]这个数在桶中的个数+1
|
|
|
|
|
while (b[a[i]] > 1) b[a[j++]]--; // 如果因为a[i]的加入,导致桶中a[i]的数量大于1
|
|
|
|
|
// 也就是有了重复,则需要从窗口左侧尝试去掉一个,看看情况会不会变好
|
|
|
|
|
// 不断刷新滑动容器长度
|
|
|
|
|
res = max(res, i - j + 1);
|
|
|
|
|
}
|
|
|
|
|
printf("%d\n", res);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|