#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=1007; const int maxm=1e6+7; int a[maxn],head,tail,q[maxm],ans; bool inq[maxm]; int main(){ int N,M;cin>>M>>N; for(int i=1;i<=N;i++){ cin>>a[i]; } for(int i=1;i<=N;i++){ if(!inq[a[i]]){ q[++tail]=a[i]; inq[a[i]]=true; ans++; } if(tail-head>M){ inq[q[head+1]]=false; head++; } } cout<<ans<<endl; return 0; }
一开始竟一直写的是tail-head>3真是面向样例编程啊