CF 1082E Increasing Frequency(贪心)】的更多相关文章

传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i]表示数字\(i\)的最大个数.那么只要\(O(n)\)的扫一遍,维护一下每个数字的\(max\),具体做法是看一下\(Max[a[i]]\)大还是\(sum[i]\)大,如果\(sum\)大的话,说明前面都不变,直接把\(Max\)赋值成\(sum[i]+1\),否则直接让\(Max[i]++\),…
题目链接 \(Description\) 给定\(n\)个数.你可以选择一段区间将它们都加上或减去任意一个数.求最终序列中最多能有多少个数等于给定的\(C\). \(n\leq5\times10^5\). \(Solution\) 先记一个表示\(C\)的个数的前缀和\(sum_i\). 选择修改的区间\([l,r]\)一定满足\(A_l=A_r\)且都是由\(A_l\)变成\(C\).所以我们枚举右端点,对每种权值单独考虑. 那么\(A_r\)要么是由前面某个等于\(A_r\)的数转移过来,要…
E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上的数同时加上或减去一个值,问最后c的最多数量为多少. 题解: 这题挺有意思的,我们通过分析题目可以发现,对于每一个d,如果把[l,r]里面的d都变为c,则最后c的数量为cnt(c,1,l-1)+cnt(c,r+1,n)+cnt(d,l,r). 这个式子变化一下,有:cnt(c,1,n)+cnt(d,…
You are given array a a of length n n . You can choose one segment [l,r] [l,r] (1≤l≤r≤n 1≤l≤r≤n ) and integer value k k (positive, negative or even zero) and change a l ,a l+1 ,…,a r  al,al+1,…,ar by k k each (i.e. a i :=a i +k ai:=ai+k for each l≤i≤…
题目大意: \(给你n个数a_i,给定一个m,你可以选择一个区间[l,r],让他们区间加一个任意数,然后询问一次操作完之后,最多能得到多少个m\) QWQ 考场上真的** 想了好久都不会,直到考试快结束才知道怎么做. 首先,根据题目,我们可以得知,假设我们修改了\([l,r]\)这个区间,那么最后的\(ans\)就应该是总的m的个数,减去区间中m的个数,加上区间内的众数的个数 QWQ 那么我们考虑怎么来处理这个. 首先,每个数字之间都是独立的. 所以我们可以预处理每一个数字出现的位置. 然后假设…
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots…
A. Increasing Sequence 题目连接: http://www.codeforces.com/contest/11/problem/A Description A sequence a0, a1, ..., at - 1 is called increasing if ai - 1 < ai for each i: 0 < i < t. You are given a sequence b0, b1, ..., bn - 1 and a positive integer…
题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, an…
Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which show…
题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*ti) 所以在新的每一秒,就把这一秒开始可以起飞的飞机中,cost最大的那一个拿出来,让他起飞就可以了 证明: 设最大的为m,我们取得另一个为n 那么n*ti+m*(ti+1) >= n*(ti+1)+m*ti 所以取m最好 这个过程用堆实现,懒得手打了,就用了priority_queue Code:…