[UVa 1619]Feel Good
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
struct node {
int num;
int pos;
};
int main() {
// freopen("input", "r", stdin);
int n;
int a[maxn], s[maxn];
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++)
cin >> a[i];
s[1] = a[1];
for (int i = 2; i <= n; i++)
s[i] = s[i - 1] + a[i];
stack<node> aa, b;
int fro[maxn], beh[maxn];
// aa.push((node){a[1], 1});
// b.push((node){a[n], n});
fro[1] = 1;
beh[n] = n;
for (int i = 1; i <= n; i++) {
node x;
if (!aa.empty())
x = aa.top();
else
x = (node){0, 0};
while (x.num >= a[i] && x.pos != i && !aa.empty()) {
aa.pop();
if (!aa.empty())
x = aa.top();
else
x = (node){0, 0};
}
aa.push((node){a[i], i});
if (x.pos != 0)
fro[i] = x.pos + 1;
else
fro[i] = 1;
}
for (int i = n; i >= 1; i--) {
node x;
if (!b.empty())
x = b.top();
else
x = (node){0, 0};
while (x.num >= a[i] && x.pos != i && !b.empty()) {
b.pop();
if (!b.empty())
x = b.top();
else
x = (node){0, 0};
}
b.push((node){a[i], i});
if (x.pos != 0)
beh[i] = x.pos - 1;
else
beh[i] = n;
}
long long ans = 0;
int L;
int R;
for (int i = 1; i <= n; i++) {
long long x = a[i] * (s[beh[i]] - s[fro[i]] + a[fro[i]]);
if (x > ans) {
ans = x;
L = fro[i];
R = beh[i];
}
}
cout << ans << endl << L << ' ' << R << endl;
}
}
[UVa 1619]Feel Good的更多相关文章
- UVA 1619 Feel Good(DP)
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...
- POJ 2796[UVA 1619] Feel Good
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16786 Accepted: 4627 Case T ...
- uva 1619 - Feel Good || poj 2796 单调栈
1619 - Feel Good Time limit: 3.000 seconds Bill is developing a new mathematical theory for human ...
- UVA 1619/POJ2796 滑窗算法/维护一个单调栈
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 12409 Accepted: 3484 Case T ...
- UVA 1619 Feel Good 感觉不错 (扫描法)
Feel Good Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Bill is deve ...
- UVA - 1619 Feel Good(扫描法)
题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- 【习题 8-18 UVA - 1619】Feel Good
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用单调队列求出l[i]和r[i] 分别表示i的左边最近的大于a[i]的数的位置以及i右边最近的大于a[i]的数的位置. 则l[i]+ ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
随机推荐
- 无法打开之前cuda的vs项目,打开之后变灰色
解决办法: 打开convolution_vs2010.vcxproj文件,将之前cuda 5.5全部改成cuda7.5. 就可以打开了.
- C#自定义工业控件开发
由于工作需要,调研过一段时间的工业控制方面的“组态软件”(SCADA)的开发,组态软件常用于自动化工业控制领域,其中包括实时数据采集.数据储存.设备控制和数据展现等功能.其中工控组件的界面展现的实现类 ...
- Asp.net导出Excel续章(自定义合并单元格,非Office组件)
结合上次写的导出Excel方法,这次上头要求我将列头进行一下合并 以前的效果: 改进后的效果: 在上篇文章中写到了Excel的导出方法,这次为了避免在生产环境中使用Office组件,服务器各种权限配置 ...
- MVC 好记星不如烂笔头之 ---> 页面压缩GIP
public class BaseController : Controller { /// <summary> /// Called before the action method i ...
- iOS NSOperation 封装 通知实现界面更新
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface MYOperation : NSOpe ...
- iOS searchbar textfield placeholder color
// Get the instance of the UITextField of the search bar UITextField *searchField = [searchBar value ...
- nodejs 提示‘xxx’ 不是内部或外部命令解决方法
本文介绍了node.js包管理工具npm安装模块后,无法通过命令行执行命令,提示‘xxx’ 不是内部或外部命令的解决方法,给需要的小伙伴参考下. 一般出现这样的问题原因是npm安装出现了问题,全局 ...
- Linux 计划任务
实例: 每5分钟定时访问一个url # crontab -e #*/5 * * * * /usr/bin/curl http://aa.com:8080/tools/sitemap.php >& ...
- uploadify前台上传文件,java后台处理的例子
1.先创建一个简单的web项目upload (如图1-1) 2.插件的准备 (1).去uploadify的官网下载一个uploadify插件,然后解压新建个js文件夹放进去(这个不强求,只要路径对了就 ...
- Leetcode Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...