没什么问题 一道简单的模拟题
#include <bits/stdc++.h>
using namespace std;
struct node{
int frequently=0,index=0;
node(int f,int i):frequently(f),index(i){}
bool operator <(const node &t)const {
return this->frequently!=t.frequently?this->frequently>t.frequently:this->index<t.index;
}
};
set<node>s;
int m[50005];
int main(){
int N,K,a;
cin>>N>>K>>a;
s.insert(node(1,a));
m[a]++;
for (int i = 1; i <N ; ++i) {
cin>>a;
printf("%d: ",a);
int k=0;
for (auto j = s.cbegin(); j !=s.cend() and k<K; ++j) {
printf("%s%d",j==s.begin()?"":" ",j->index);
++k;
}
printf("\n");
auto it=s.find(node(m[a],a));
if (it!=s.end())
s.erase(it);
s.insert(node(++m[a],a));
}
return 0;
}