#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <cctype>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 1000005;
set <int> p;
map <int ,int>q;
int a[N];
int main()
{
int n, i, s;
while(scanf("%d", &n)!=EOF)
{
p.clear();
q.clear();
for(i = 0 ; i<n; i++)
{
scanf("%d", &a[i]);
p.insert(a[i]);
}
s = p.size();
int ans = n;
int l = 0 , r = 0, sum = 0;
while(l < n && r < n)
{
if(q[a[r]]==0)
sum++;
q[a[r]]++;
while(q[a[l]]>=2)
{
q[a[l]]--;
l++;
}
if(sum == s)
{
ans = min(ans , r - l + 1);
if(q[a[l]]==1) sum--;
q[a[l]]--;
l++;
}
r++;
}
printf("%d\n", ans);
}
return 0;
}
poj 3320
最新推荐文章于 2021-10-14 20:07:21 发布