【题意概述】
给出N个数(10^6),求出最短的包含1~M(M≤2000)的连续子序列
【题解】
Two Pointer~~~
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 const int maxn=1000010; 5 int n,m,ans=0X7f7f7f7f,l,r,a[maxn],v[maxn],now,al,ar; 6 void read(int &k){ 7 k=0; int f=1; char c=getchar(); 8 while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); 9 while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar(); 10 k*=f; 11 } 12 int main(){ 13 read(n); read(m); 14 for (int i=1;i<=n;i++) read(a[i]); 15 while (l<n){ 16 while(now<m&&r<n) if (!v[a[++r]]++) now++; 17 if (now==m&&ans>r-l) ans=r-l,al=l+1,ar=r; 18 if (!--v[a[++l]]) now--; 19 } 20 return printf("%d %d",al,ar),0; 21 }