F - Distinct Numbers】的更多相关文章

题意 给出一个长度为NNN的序列,求对于所有k∈[1,N]k\in[1,N]k∈[1,N],每次从序列中选出kkk个互不相同的数,最多能取多少次. N≤3e5N\le3e5N≤3e5 题解 我们首先把数组转化为相同的数的出现次数的序列,如序列(1,3,4,4)(1,3,4,4)(1,3,4,4)就转化为(1,1,2)(1,1,2)(1,1,2).把这个得到的序列计作aaa. 然后二分答案,假设当前二分到xxx,能取xxx次的条件是: (∑ai≤xai)+x⋅∑ai>x1≥k⋅x\large(\s…
链接:https://atcoder.jp/contests/abc143/tasks/abc143_f 题解:开两个数组,其中一个arr用来保存每个元素出现的次数,同时再开一个数组crr用来保存出现次数等于其下标的个数,然后对crr求前缀和,crr就变成了出现次数维护小于其小标的总个数. 根据题意:每次取k个,k个元素各不相同,问最多可以取多少次,假设可以取 x次,为了保证每个元素不相同,那么每个元素出现的次数最多为x次,并且总个数为k*x,因此这里可以用二分来判断. AC代码: //crr[…
这道题非常好.其思想类似于 $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) {…
Distinct Subsequences OJ: https://oj.leetcode.com/problems/distinct-subsequences/ Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string…
A. Numbers Joke time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output   Input The input contains a single integer a (1 ≤ a ≤ 30). Output Output a single integer. Example Input 3 Output 27 题目链接:ht…
F. Building Numbers   time limit per test 3.0 s memory limit per test 256 MB input standard input output standard output In this problem, you can build a new number starting from 1, by performing the following operations as much as you need: Add 1 to…
一直直到bug-free.不能错任何一点. 思路不清晰:刷两天. 做错了,刷一天. 直到bug-free.高亮,标红. 185,OA(YAMAXUN)--- (1) findFirstDuplicate string in a list of string. import java.util.HashSet; import java.util.Set; public class Solution { public static void main(String[] args) { String[…
Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   Special Judge Description Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every t…
一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit s…
414. Third Maximum Number 给一个非空的整数数组,找到这个数组中第三大的值,如果不存在,那么返回最大的值.要求时间复杂度为o(n) 例如: Example 1: Input: [3, 2, 1] Output: 1 Explanation: The third maximum is 1. Example 2: Input: [1, 2] Output: 2 Explanation: The third maximum does not exist, so the maxi…