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 ...
随机推荐
- The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online(2018 青岛网络预选赛)
A题 A Live Love 原题链接:https://pintia.cn/problem-sets/1036903825309761536/problems/1041155943483625472 ...
- 未AC
Count the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Spring——注解
一.IOC注解 1.用于向Spring容器中注入bean: @Component:向Spring容器中注入bean @Repository:用于标注Dao层 @Service:用于标注Service业 ...
- jQuery选择器(6)
一:基本选择器 标签选择器:$("标签名"); 返回一组元素集合(匹配相同的标签名) 类选择器:$(".class类名"); 返回一组元素集合(匹配相同的cla ...
- error while loading shared libraries: libXXXX.so: cannot open shared object file: No such file or directory
出现这个问题的原因是运行程序缺少依赖库,或者运行程序的依赖库缺少依赖库,可能你的本地目录下面就有这个库文件,但是linux搜索路劲不会从当前路径下去搜索:这种情况可能出现在切换环境上,可能你在一个li ...
- pl/sql 过程 函数(写一个过程,输入部门编号,在控制台打印这个部门的名称,总人数,平均工资(基本工资+奖金))
1.编写过程,输入三角形三个表的长度.在控制台打印三角形的面积. create or replace procedure pro_s(v_a number,v_b number,v_c number) ...
- IDEA找回Run Dashboard
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
- FinalCutPro快捷键
FinalCutPro快捷键使用 FinalCutPro的快捷键使用十分有用,特对一些基本的快捷键进行了总结 1)i:截取片段开始Initial 2)o: 截取片段结束Over i和o可以在一个素材片 ...
- koa 基础(二十一)nodejs 操作mongodb数据库 --- 查询数据
1.app.js /** * nodejs 操作mongodb数据库 * 1.安装 操作mongodb * cnpm install mongodb --save * 2.引入 mongodb 下面的 ...
- 在WPF中使用AForge控件
AForge.NET 是用C#写的一个关于计算机视觉和人工智能领域的框架,它包括图像处理.神经网络.遗传算法和机器学习等. 要实现视频功能,需要使用AForge.Controls命名空间中的Video ...