POJ2796 单调队列
Feel Good
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 8041 | Accepted: 2177 | |
Case Time Limit: 1000MS | Special Judge |
Description
A new idea Bill has recently developed assigns a non-negative integer value to each day of human life.
Bill calls this value the emotional value of the day. The greater the emotional value is, the better the daywas. Bill suggests that the value of some period of human life is proportional to the sum of the emotional values of the days in the given period, multiplied by the smallest emotional value of the day in it. This schema reflects that good on average period can be greatly spoiled by one very bad day.
Now Bill is planning to investigate his own life and find the period of his life that had the greatest value. Help him to do so.
Input
Output
Sample Input
6
3 1 6 4 5 2
Sample Output
60
#include <cstdio>
#include <deque>
#include <iostream> using namespace std; int a[],l[],r[];
long long sum[]; struct Type{
int res,data;
}; int main()
{
int n;
scanf("%d",&n);
for(int i=; i<=n; i++){
scanf("%d",&a[i]);
sum[i]=sum[i-]+a[i];
} deque<Type> p;
p.clear();
for(int i=; i<=n; i++){
while(!p.empty()&&p.back().data>=a[i])
p.pop_back();
if(p.empty()) l[i]=; else l[i]=p.back().res+;
Type t;
t.res=i;
t.data=a[i];
p.push_back(t);
} p.clear();
for(int i=n; i>=; i--){
while(!p.empty()&&p.back().data>=a[i])
p.pop_back();
if(p.empty()) r[i]=n; else r[i]=p.back().res-;
Type t;
t.res=i;
t.data=a[i];
p.push_back(t);
} // for(int i=1; i<=n; i++)
// printf("%d %d\n",l[i],r[i]); long long ans=;
int ansi;
for(int i=; i<=n; i++)
if(ans<=(sum[r[i]]-sum[l[i]-])*a[i]){
ans=(sum[r[i]]-sum[l[i]-])*a[i];
ansi=i;
} printf("%I64d\n",ans);
printf("%d %d\n",l[ansi],r[ansi]); return ;
}
POJ2796 单调队列的更多相关文章
- POJ2796 Feel Good -- 单调队列
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 4015 Case T ...
- BestCoder Round #89 B题---Fxx and game(单调队列)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5945 问题描述 输入描述 输出描述 输入样例 输出样例 题意:中文题,不再赘述: 思路: B ...
- 单调队列 && 斜率优化dp 专题
首先得讲一下单调队列,顾名思义,单调队列就是队列中的每个元素具有单调性,如果是单调递增队列,那么每个元素都是单调递增的,反正,亦然. 那么如何对单调队列进行操作呢? 是这样的:对于单调队列而言,队首和 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
- BZOJ 1047 二维单调队列
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 题意:见中文题面 思路:该题是求二维的子矩阵的最大值与最小值的差值尽量小.所以可以考 ...
- 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...
- BZOJ1047: [HAOI2007]理想的正方形 [单调队列]
1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2857 Solved: 1560[Submit][St ...
- hdu 3401 单调队列优化DP
Trade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 【转】单调队列优化DP
转自 : http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列是一种严格单调的队列,可以单调递增,也可以单调递减.队 ...
随机推荐
- Python的map、filter、reduce函数 [转]
1. map函数func作用于给定序列的每个元素,并用一个列表来提供返回值. map函数python实现代码: def map(func,seq): mapped_seq = [] fo ...
- reset内容
/*reset */div,p,a,span,body,dl,dt,dd,header,footer,img,section,time,h2,em,article,h3,h4,ul,li,labe ...
- HDU1002 -A + B Problem II(大数a+b)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- [设计模式] 15 解释器模式 Interpreter
在GOF的<设计模式:可复用面向对象软件的基础>一书中对解释器模式是这样说的:给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子.如果一种特定类 ...
- ReplicaManager之DelayedOperation
DelayedOperation包括两种:DelayedFetch和DelayedProduce,它们的存在是由Kafka Protocol决定的,而Kafka Protocol是由实际需求决定的…… ...
- hdoj 1596 find the safest road
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1596 分析:Dijkstra变体,最短路径判断计算方式:Safe(P) = s(e1)*s(e2)…* ...
- 荣耀3X畅玩版狙击红米note!
华为与小米的战争史,可以追溯到 红米 799,华为独立初荣耀品牌推出荣耀3C,定价798,就是比你少一快; 小米3 定价1999,华为出荣耀3X,定价1980; 最近的红米Note,标配版定价799, ...
- iOS动画篇:UIView动画
iOS的动画效果一直都很棒很,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,对于简单的应用场景,我们可以使用UIKit提供的动画来实现. UIView动画 ...
- 测试Tomcat
- 枚举桌面应用程序lnk路径并得到对应程序的绝对路径(使用SHGetDesktopFolder函数枚举,然后使用COM查询IShellFolder,IShellLink和IPersistFile接口)
// 枚举桌面上应用程序的lnk路径 void EnumDesktopLnkPath() { WCHAR szPath[MAX_PATH] = {0}; SHGetSpecialFolderPathW ...