Non-negative Partial Sums(单调队列)】的更多相关文章

Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1420    Accepted Submission(s): 544 Problem Description You are given a sequence of n numbers a0,..., an-1. A cyclic shi…
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2622    Accepted Submission(s): 860 Problem Description You are given a sequence of n numbers a0,..., an-1. A cyclic shi…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4193 题目大意: 给n个数,a0,a1,...an,求ai,ai+1,...an,a1,a2,...ai-1这样的排列种数,使得所有的前k(1<=k<=n)个的和都大于等于0: 解题思路: 求前缀和,加倍序列. 要满足前k个和都>=0,只需最小值>=0,所以用单调队列维护一个最小的前缀和sum[i],(i>=j-n+1),这样就保证了sum[j]-sum[i]最大,所以区间[j…
HDU 4193 题意:给n个数字组成的序列(n <= 10^6).求该序列的循环同构序列中,有多少个序列的随意前i项和均大于或等于0. 思路: 这题看到数据规模认为仅仅能用最多O(nlogn)的算法.然后想到了之前刚做过的有关最小表示法的题.但还没证明出一个做这题有效的算法出来. 后来看过题解.发现用的最多的方法是单调队列,然而我对这个知识点知之甚少orz /*科普君:from单调队列 单调队列是指:队列中元素之间的关系具有单调性.并且,队首和队尾都能够进行出队操作.仅仅有队尾能够进行入队操作…
 题目大意: 给定一个长度为n的循环序列.从n个不同位置開始,问有几个位置使得一下情况成立:全部前缀的和都大等于0(n <=1000000). 下午的训练赛.之前没学过单调队列所以用的线段树,一直tle,到了结束也没搞出来.晚上回来看了下,能够用单调队列来做.时间复杂度为O(n). 这道题事实上就是看从每一个位置開始的最小前缀和是否大于零.可是这是有规律的. 比方从元素1(下面将元素a[i]简写为i)開始的全部前缀和为1,1+2,...,1+2+3+..+n 从2開始的全部前缀和为2, 2+…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4193 题意: 给定序列,可以把后面的连续的部分移到最前面来,问多少种移法使得最终得到的序列的前i项和均大于等于0(1≤i≤n)? 分析: 先将数组前后拼接起来,记录每个位置的前缀和.然后去找长度为n的滑动窗口,在这个窗口内,要保证前i项和大于等于0,也即区间[i,n+i]之间的找到的最小的前缀和要比a[i−1]大.而不涉及修改,这个最小前缀和的获取和维护就利用单调队列即可~ 代码: #includ…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2490 Parade Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 902    Accepted Submission(s): 396 Problem Description Panagola, The Lord of city F lik…
Description Panagola, The Lord of city F likes to parade very much. He always inspects his city in his car and enjoys the welcome of his citizens. City F has a regular road system. It looks like a matrix with n+1 west-east roads and m+1 north-south r…
A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1. In the festival m fireworks will be launched. The i-…
Neko has a loop of size nn. The loop has a happy value aiai on the i−th(0≤i≤n−1)i−th(0≤i≤n−1) grid. Neko likes to jump on the loop.She can start at anywhere. If she stands at i−thi−thgrid, she will get aiai happy value, and she can spend one unit ene…