[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
随机推荐
- MSSQL-to-MySQL v5.3, 从MSSQL迁移到mySQL的最佳工具
将现有的MSSQL数据库迁移到MySQL数据库,尝试了很多种工具 MySQL Workbench / MSSQL to MySQL Export / DB Converter / openDBcopy ...
- FluentValidation
git :https://github.com/JeremySkinner/FluentValidation Example using FluentValidation; public class ...
- Java实现JDBC连接数据库实例
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...
- .NET Attributes
Attributes 特性 公共语言运行时允许添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注,如类型.字段.方法和属性等.Attributes和Microso ...
- .NET 反射概述
反射 反射提供了封装程序集.模块和类型的对象(Type 类型).可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性.如果代码中使用了属性 ...
- svn工具安装下载Tomcat源码以及导入eclipse
安装 1.svn下载地址 https://tortoisesvn.net/downloads.html 2.语言包下载 3.先安装svn,在直接安装语言包 4.桌面右键可以看到相关svn信息 下载To ...
- 话说IOC(DI)
什么是IOC(DI) 书上的东东,因为说的太严谨,所以不太容易懂,其实也没那么复杂. 举几个例子: 1.文明点的:中午太热,不想出去吃饭,所以希望同事能帮忙带饭,现在有了点外卖平台,我们就可以直接在网 ...
- Source Insight编辑器配置
Sublime Text 无疑是一款很优秀的编辑器和阅读器,可惜对于中文编码不支持,网上的ConvertTOUTF8存在BUG,经常转码失败,体验很不好. 现在开始使用source insight,这 ...
- js文件上传
DOM: <form id="clueForm" class="insert-dialog" action="/xxx/xxx"met ...
- Bestcoder Round #84
A题 Aaronson http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=718&pid=1001 感觉一 ...