尺取法,错题
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include<queue>
#include <math.h>
#include<map>
#include<deque>
using namespace std;
int s[1000100];
int h[1000100];
int main()
{
int P;
scanf("%d", &P);
int num = 0;
map<int, int>awa;
for (int i = 0; i < P; i++)
{
scanf("%d", &h[i]);
if (!awa[h[i]])
{
num++;
awa[h[i]]=num;
}
}
int l = 0, r = 0,t=1;
int mn = 1000100;
s[awa[h[0]]]++;
while (l <= r && r < P)
{
if (t == num)
{
mn = min(mn, r-l+1);
s[awa[h[l]]]--;
if (s[awa[h[l]]] == 0)
t--;
l++;
}
else
{
r++;
s[awa[h[r]]]++;
if (s[awa[h[r]]] == 1)
t++;
}
}
cout << mn;
}