tj(ac)
2025-07-27 20:24:27
发布于:上海
0阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
queue<int> st;
queue<int> q;
int m, n, x, ans;
bool t[10005];
int main(){
cin >> m >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
if (t[x]){
continue;
}
if (st.size()>=m) { //如果队列st的元素个数 >= m
t[st.front()] = 0;
st.pop();
}
st.push(x);
t[x] = 1;
ans++; //查词典的次数 + 1
}
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个