[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
随机推荐
- go:interface{}、断言与类型转换
interface{}可用于向函数传递任意类型的变量,但对于函数内部,该变量仍然为interface{}类型(空接口类型), 不清楚这点将可能导致错误.如以下代码: package main impo ...
- mysql数据库视图连接出现2003····错误
MySQL利用视图工具连接数据库时出现2003····错误 原因:MySQL的服务没有开启 解决步骤: ...
- gulp基本介绍
一.gulp是什么 gulp就是用来机械化的完成重复性质(如less->css:js.css压缩:js混淆)的工作:gulp的机制就是将重复工作抽象成一个个的任务. 二.gulp使用 a.首先确 ...
- October 19th Week 43rd Wednesday, 2016
I find that the harder I work, the more luck I seem to have. 越努力,越幸运. However, I find that the harde ...
- VS更改编辑窗背景
打开Visual Studio 工具→扩展和更新→联机 在搜索框里输入“background”后,搜索结果有很多插件可以更改 Visual Studio 的背景,选择其中的一项,可以在右边进行预览 ...
- Word2vec多线程(tensorflow)
workers = [] for _ in xrange(opts.concurrent_steps): t = threading.Thread(target=self._train_thread_ ...
- 【Java EE 学习 24 下】【注解在数据库开发中的使用】【反射+注解+动态代理在事务中的应用service层】
一.使用注解可以解决JavaBean和数据库中表名不一致.字段名不一致.字段数量不一致的问题. 1.Sun公司给jdbc提供的注解 @Table.@Column.@Id.@OneToMany.@One ...
- linux协议栈skb操作函数
- [译]:Orchard入门——Orchard控制面板概览
原文链接:Getting Around the Dashboard 文章内容基于Orchard 1.8版本 Orchard控制面板用于管理网站.改变外观.添加内容以及控制Orchard功能可用性.成功 ...
- Mac安装软件报“打不开。。。,因为它来自身份不明的开发者”的解决办法
问题描述 在Mac上安装git,双击pkg进行安装,报如下图错误: 解决办法 不要双击pkg文件,改成选中文件之后,鼠标右键,选择“打开方式->安装器(默认)”,即可继续安装.