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 单调队列是一种严格单调的队列,可以单调递增,也可以单调递减.队 ...
随机推荐
- JS实现刷新iframe的方法
<iframe src="1.htm" name="ifrmname" id="ifrmid"></iframe> ...
- Careercup - Google面试题 - 4807591515389952
2014-05-06 00:45 题目链接 原题: What would happen if you have only one server for a web cache (a web brows ...
- webview加载本地html
//webView.loadUrl("file:///android_asset/index.html"); 加载assets目录中含有的index.html webView.l ...
- axure7.0 汉化包下载
下载地址:http://files.cnblogs.com/files/feijian/axure7.0%E4%B8%AD%E6%96%87%E8%AF%AD%E8%A8%80%E6%B1%89%E5 ...
- C# 越来越复杂了
自从三年前来到现在的公司以后,基本上不怎么使用.NET进行开发了.但最近因为公司有个CRM的项目,所以只有重新检起.NET进行开发. 因为近3年没有搞.NET的开发了,因此也不敢乱整个框架,在看了一周 ...
- shell 学习基地
http://blog.csdn.net/column/details/shell-daily-study.html?&page=2
- Jqgrid使用
$('#mygrid').jqGrid('GridUnload'); //保留table元素 $('#mygrid').jqGrid('GridDestroy '); //相当于remove,移除 ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- BZOJ1692: [Usaco2007 Dec]队列变换
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 594 Solved: 246[Submit][Sta ...
- [设计模式] 13 责任链模式 Chain of Responsibility
转 http://blog.csdn.net/wuzhekai1985 http://www.jellythink.com/archives/878 向项目经理提交了休假申请,我的项目经理向 ...