ABC143F Distinct Numbers
这道题非常好。其思想类似于 $O(n \log n)$ 求最长上升子序列的算法。
hint:考虑固定操作次数 $o$,$k$ 最大可取到多少?
int n;
scan(n);
vi a(n);
scan(a);
// appearance[i]: i 出现的次数
vi appearance(n + 1);
FOR (x, a) {
appearance[x]++;
}
// sum[i]:出现不超过i次的数,出现的总次数
vi sum(n + 1);
FOR (x, appearance) {
sum[x] += x;
}
rng (i, 2, n + 1) {
sum[i] += sum[i - 1];
}
vi cnt(n + 1);
FOR (x, appearance) {
cnt[x]++;
}
// cnt[i]:出现次数大于等于i的数字的个数
down (i, n - 1, 1) {
cnt[i] += cnt[i + 1];
}
// max_k[i]: 固定操作次数i,k最大可取到多少
vi max_k(n + 2);
max_k[0] = n;
max_k[n + 1] = 0;
// max_k[] 单调不增,max_k[i] >= max_k[i + 1]
rng (i, 1, n + 1) {
max_k[i] = cnt[i] + sum[i - 1] / i;
}
down (i, n, 0) {
rng (j, max_k[i + 1] + 1, max_k[i] + 1) {
println(i);
}
}
ABC143F Distinct Numbers的更多相关文章
- AtCoder Beginner Contest 143 F - Distinct Numbers
题意 给出一个长度为NNN的序列,求对于所有k∈[1,N]k\in[1,N]k∈[1,N],每次从序列中选出kkk个互不相同的数,最多能取多少次. N≤3e5N\le3e5N≤3e5 题解 我们首先把 ...
- F - Distinct Numbers
链接:https://atcoder.jp/contests/abc143/tasks/abc143_f 题解:开两个数组,其中一个arr用来保存每个元素出现的次数,同时再开一个数组crr用来保存出现 ...
- 30. Distinct Subsequences
Distinct Subsequences OJ: https://oj.leetcode.com/problems/distinct-subsequences/ Given a string S a ...
- [LeetCode] Missing Number 丢失的数字
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...
- [LeetCode] Remove Duplicates from Sorted List II 移除有序链表中的重复项之二
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...
- BUG-FREE-For Dream
一直直到bug-free.不能错任何一点. 思路不清晰:刷两天. 做错了,刷一天. 直到bug-free.高亮,标红. 185,OA(YAMAXUN)--- (1) findFirstDuplicat ...
- [leetcode]题型整理之用bit统计个数
137. Single Number II Given an array of integers, every element appears three times except for one. ...
- CF2.C
C. Vladik and fractions time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- 未关闭虚拟机直接关闭vmware引发的一系列问题——Windows下linux虚拟机
虚拟机长时间挂起重新打开时卡顿,无法开启,脑抽直接关闭了vmware软件引起的一系列问题. 原因是关闭了vmware,但是相应的虚拟机并没有关闭,所以虚拟机不能重开 会出现如下提示 解决方案如下: 1 ...
- jq获取页面中checkbox已经选中的checkbox
var len=$("input[name='bike']:checked").length; //len为0未选中
- Apache 服务器 首次访问特别慢的解决过程,php环境
一台服务器之前装的是java的tomcat apache 项目, 后面装了个phpstudy 在上面,访问php项目发现 浏览器首次打开网页需要7-8秒,打开成功后连续访问都很快,过一段时间访问又是7 ...
- R-aggregate()
概述 aggregate函数应该是数据处理中常用到的函数,简单说有点类似sql语言中的group by,可以按照要求把数据打组聚合,然后对聚合以后的数据进行加和.求平均等各种操作. x=data.fr ...
- python3精品解析运算符
算数运算符 +:两个对象相加 -:得到负数或者,或者一个数减去另一个数 *:两个数相乘或者是返回一个被重复若干次的字符串 /:5/2等于2.1 5//2=2(/有余数,//取整) %:取模(5%2=1 ...
- React Redux 与胖虎
这是一篇详尽的 React Redux 扫盲文. 对 React Redux 已经比较熟悉的同学可以直接看 <React Redux 与胖虎他妈>. 是什么 React Redux 是 R ...
- 修复Long类型太长转为JSON格式的时候出错的问题
这边项目要求ID是自动生成的20位Long型数字 但是实际中应用的时候回发生一种问题就是,查询的时候debug的时候数据都正常,但是返回前端的时候就会发现,数据错误了. 大体就是类似于下面的这种情况. ...
- linux安装vlc视频播放器
文章来自转发 最近,打算在centos7.2上安装一个叫MPlayer的视频播放器,但是折腾好久,得到的结果只是可以播放,但是却没有声音.无奈之下另寻他路.最后选择安装VLC视频播放器. 我的linu ...
- FastAdmin 在 CRUD 时出现 exec() has been disabled for security reasons 处理方法
然后在看看 禁用函数列表(php.ini)disable_functions = proc_open, popen, exec, system, shell_exec, passthru 这里要把 e ...
- router 配置按需加载对应的组件,配置active
const routes = [ { path: '/', component: App, children: [ {path: '/index/:type', name: 'index', comp ...