[ABC329D] Election Quick Report 题解
题意
每次输入一个数
思路
设当前最大值的编号为
时间复杂度:
Code
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
int a[N], tot[N], maxn, id;
//tot 统计次数, maxn 为最大值, id为最大值的编号
signed main(){
cin >> n >> m;
for (int i = 1; i <= m; i ++) {
cin >> a[i];
tot[a[i]] ++;
if(tot[a[i]] > maxn) {
maxn = tot[a[i]], id = a[i];
}else if(tot[a[i]] == maxn && a[i] < id){
id = a[i];
}
cout << id << endl;
}
return 0;
}