B1. Social Network (easy version)【1000 / 队列模拟】

B1. Social Network (easy version)【1000 / 队列模拟】
https://codeforces.com/problemset/problem/1234/B1

#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
int a[N],n,k;
unordered_map<int,int>st;
queue<int>q;
int main(void)
{
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(st[a[i]]) continue;
		else 
		{
			if(q.size()<k) q.push(a[i]),st[a[i]]=1;
			else
			{
				auto temp=q.front(); q.pop();
				q.push(a[i]);
				st[temp]=0;
				st[a[i]]=1;
			};
		}
	}
	cout<<q.size()<<endl;
	vector<int>ve;
	while(q.size()) ve.push_back(q.front()),q.pop();
	for(int i=ve.size()-1;i>=0;i--) cout<<ve[i]<<" ";
	return 0;
}
上一篇:实验1 8086汇编指令编码和调试


下一篇:python自动获取steam验证码