-
Notifications
You must be signed in to change notification settings - Fork 0
/
1129.cpp
53 lines (52 loc) · 1.24 KB
/
1129.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/10/16.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <set>
#include <deque>
using namespace std;
struct node{
int num, cnt;
node(int num, int cnt):num(num),cnt(cnt){}
bool operator < (const node &a)const{ // 重载运算符
return cnt != a.cnt ? cnt > a.cnt : num < a.num;
}
};
set<node> s;
int times[50001]={0}, n, k;
int main(){
scanf("%d%d",&n,&k);
int num;
for(int i = 0; i < n; i++){
scanf("%d",&num);
if(i){
printf("%d:",num);
int cnts = 0; // 记录输出的次数
for(auto it = s.begin(); cnts < k && it != s.end(); it++){
printf(" %d",it->num);
cnts++;
}
printf("\n");
}
auto it = s.find(node(num,times[num])); // 判断set中是否存在
if(it != s.end()) s.erase(it);
times[num]++; // 更新浏览次数
s.insert(node(num,times[num]));
}
return 0;
}