跳到正文

题解

题解:P16460 [UOI 2026] Minimum Deletion

xiaozhengguoaaa约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年5月14日
收录
2026年5月31日
更新
2026年11月13日
篇幅
约 3 分钟
题目
P16460

版本

  1. v1当前

做完这道题我深刻的意识到了我是区这件事。

我是可爱的区区区。

思路

要求数组的 mex≤k\text{mex}\le k,只需在 0∼k0\sim k 中存在一个整数完全不在数组中出现。

把某个数彻底删去的代价等于该数的出现次数,所以只需在 0≤x≤k0\le x\le k 中找到出现次数的最小值,就是最少的删除操作次数。

AC code
C++
#include <bits/stdc++.h>
#define int long long
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 4e6 + 7;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
// const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
// const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int dx[] = {-1 , 1 , 0 , 0} ;
const int dy[] = {0 , 0 , -1 , 1} ;

inline int read ()
{
	int s = 0 , w = 1 ;
	char ch = getchar () ;
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			w = -1;
		ch = getchar () ;
	}
	while (ch >= '0' && ch <= '9')
	{
		s = s * 10 + ch - '0' ;
		ch = getchar ();
	}
	return s * w ;
}
inline void write (int x)
{
	if (x < 0) putchar ('-') , x = -x ;
	if (x > 9) write (x / 10) ;
	putchar (x % 10 + '0') ;
	return ;
}

int a[N] , b[N] ;

int ans = INF ;

signed main()
{
	fst ;
	int n , k ;
	cin >> n >> k ;
	for (int i = 1 ; i <= n ; i ++)
	{
		cin >> a[i] ;
		b[a[i]] ++ ;
	}
	for (int i = 0 ; i <= k ; i ++)
	{
		ans = min(ans , b[i]) ;
	}
	cout << ans ;
    return 0;
}
原文