luogu1540 [NOIp2011]机器翻译 (队列)

时间:2023-03-08 17:05:43
 #include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=,maxm=; inline ll rd(){
ll x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} queue<int> q;
int N,M;
bool ins[maxn]; int main(){
//freopen("","r",stdin);
int i,j,k,ans=;
M=rd(),N=rd();
for(i=;i<=N;i++){
int x=rd();
if(!ins[x]){
ans++;
if(q.size()>=M){
ins[q.front()]=;q.pop();
}
ins[x]=;q.push(x);
}
}
printf("%d\n",ans);
return ;
}