题目:

思路:

预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了。

这个预处理的技巧巧妙的用了之前的处理结果。(大佬tql)

代码:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define MAX 1e3
#define FRE() freopen("in.txt","r",stdin)
#define FRO() freopen("out.txt","w",stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int maxn = ;
int r[maxn],l[maxn];
ll sum[maxn],a[maxn];
int n; int main(){
FRE();
int kase = ;
while(scanf("%d",&n)!=EOF){
sum[] = ;
a[] = a[n+] = -;
for(int i=; i<=n; i++){
scanf("%lld",&a[i]);
sum[i] = sum[i-]+a[i];
l[i] = r[i] = i;
} for(int i=; i<=n; i++){//根据已经得到的范围快速求出当前的最小值范围
while(a[i] <= a[l[i]-]){
l[i] = l[l[i]-];
}
} for(int i=n; i>=; i--){
while(a[i] <= a[r[i]+]){
r[i] = r[r[i]+];
}
} int L=,R=;//当不知道具体的边界的时候,就将边界设为开头
ll ans = a[]*a[];
for(int i=; i<=n; i++){
ll tsum = sum[r[i]] - sum[l[i]-];
if(ans < tsum * a[i]){
L = l[i];
R = r[i];
ans = tsum*a[i];
}
}
if(kase++){
printf("\n");
}
printf("%lld\n",ans);
printf("%d %d\n",L,R);
}
return ;
}

UVA - 1619 Feel Good(扫描法)的更多相关文章

  1. POJ 2796 / UVA 1619 Feel Good 扫描法

    Feel Good   Description Bill is developing a new mathematical theory for human emotions. His recent ...

  2. UVA 1619 Feel Good 感觉不错 (扫描法)

    Feel Good Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Bill is deve ...

  3. UVA 1619 Feel Good(DP)

    Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...

  4. POJ 2796[UVA 1619] Feel Good

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16786   Accepted: 4627 Case T ...

  5. uva 1619 - Feel Good || poj 2796 单调栈

    1619 - Feel Good Time limit: 3.000 seconds   Bill is developing a new mathematical theory for human ...

  6. [UVa 1619]Feel Good

    #include <bits/stdc++.h> using namespace std; const int maxn = 1000010; struct node { int num; ...

  7. UVA 1619/POJ2796 滑窗算法/维护一个单调栈

    Feel Good Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12409   Accepted: 3484 Case T ...

  8. 【习题 8-18 UVA - 1619】Feel Good

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用单调队列求出l[i]和r[i] 分别表示i的左边最近的大于a[i]的数的位置以及i右边最近的大于a[i]的数的位置. 则l[i]+ ...

  9. 紫书 习题8-18 UVa 11536 (扫描法)

    这道题貌似可以用滑动窗口或者单调栈做, 但是我都没有用到. 这道题要求连续子序列中和乘上最小值最大, 那么我们就可以求出每一个元素, 以它为最小值的的最大区间的值, 然后取max就ok了.那么怎么求呢 ...

随机推荐

  1. PDO连接mysql8.0报PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers错误

    安装mysql8.0之后,尝试使用php连接mysql,总是报PDO::__construct(): Server sent charset (255) unknown to the client. ...

  2. Oracle高水位线

    Oracle高水位线 https://blog.csdn.net/jx_jy/article/details/50607790 Oracle高水位线的概念 Oracle里面的对象放到存储级别都称为se ...

  3. 17年day4

    /* 嗯,又一天 上午考试,睡了两觉(我不会把我第二觉流了口水这件事说出去) 状态比较玄学,上午困得要死,下午无比精神(感觉NOIP要完). 复习了概率期望.发现以前做过的题还是不会做,好像连印象都比 ...

  4. UVa 101 - The Blocks Problem STL

    题目:给你n个方块,有四种操作: .move a onto b,把a和b上面的方块都放回原来位置,然后把a放到b上面: .move a over b,把a上面的放回原处,然后把a放在b所在的方块堆的上 ...

  5. Rabin_Karp(hash) HDOJ 1711 Number Sequence

    题目传送门 /* Rabin_Karp:虽说用KMP更好,但是RK算法好理解.简单说一下RK算法的原理:首先把模式串的哈希值算出来, 在文本串里不断更新模式串的长度的哈希值,若相等,则找到了,否则整个 ...

  6. php 报错如下:Notice: Trying to get property of non-object

    参考文档如下解决: https://stackoverflow.com/questions/5891911/trying-to-get-property-of-non-object-in 问题如下: ...

  7. [转]深入ASP.NET MVC之二:路由模块如何工作

    本文转自:http://www.cnblogs.com/yinzixin/archive/2012/11/05/2754483.html 摘要: 上文分析了UrlRouting模块何时会被触发,本文重 ...

  8. Silverlight环境配置

    今天对Silverlight安装环境进行了配置,本系统已经安装VS2010 和 Silverlight 5. 要开发Silverlight必须安装Developer Runtime 和 SDK , 且 ...

  9. Mui使用jquery并且使用点击跳转新窗口

    网上好多朋友是这样做的: 全局插入了js代码 mui('body').on('tap', 'a', function () { document.location.href = this.href; ...

  10. PostgreSQL与MySQL比较

    特性 MySQL PostgreSQL 实例 通过执行 MySQL 命令(mysqld)启动实例.一个实例可以管理一个或多个数据库.一台服务器可以运行多个 mysqld 实例.一个实例管理器可以监视 ...