直接手写队列+哈希
#include<iostream>
#define N 1010
using namespace std;
int n,m;
int t[N*N];
int main()
{
cin>>n>>m;
int q[N*N];
int hh = 0 , tt = 0;
int res = 0;
while(m --)
{
int a;
cin>>a;
if(t[a]) continue;
if(tt < n)
{
res ++;
q[tt ++] = a;
t[a] = true;
continue;
}
if(tt - hh == n)
{
t[q[hh ++]] = false;
res ++;
q[tt ++] = a;
t[a] = true;
}
}
cout<<res<<endl;
return 0;
}