# 众数 I## 题目背景pigstd 是一个可爱的男孩子。他在 NOI2022 中的众数一题定义了 $10^6$ 个 stddeque 并没有 MLE。## 题目描述给定一个长度为 $n$ 的序列 $a$我们通过以下方式构造序列 $b$:- 初始时 $b=a$。- 依次对 $b$ 进行 $k$ 次操作每次操作选择任意一个元素并将其修改为任意整数。dXqwq 定义一个序列的众数为所有出现次数最大的
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
unordered_map<int, int> count;
for (int i = 0; i < n; i++) {
cin >> a[i];
count[a[i]]++;
}
int maxCount = 0;
for (auto it = count.begin(); it != count.end(); it++) {
maxCount = max(maxCount, it->second);
}
int possibleCount = 0;
for (auto it = count.begin(); it != count.end(); it++) {
if (it->second == maxCount) {
possibleCount++;
}
}
if (k == 0 || possibleCount == 1) {
cout << possibleCount << endl;
} else {
cout << "pigstd" << endl;
}
return 0;
}
``
原文地址: http://www.cveoy.top/t/topic/h5oR 著作权归作者所有。请勿转载和采集!