题目:

思路:

预处理出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. delphi中URL的汉字编码

    delphi中URL的汉字编码 show.asp?sort=全部&sortlevel=1&gorq=供&n=5&sitename=全部&img=yes& ...

  2. mongodb AND查询遇到多个index时候可能会做交集——和复合索引不同

    关于MongoDB中索引文档的一个问题? - To illustrate index intersection, consider a collection orders that has the f ...

  3. pycharm打开多个项目并存

    问题: 有时我们需要打开多个项目,而现在的做法是:  原有的a项目不动,新打开一个pycharm来打开b项目, 或者 在原有的a项目中打开b项目并覆盖a项目,即a项目与b项目不能共存 需求: 有时我们 ...

  4. 洛谷 P1969 积木大赛 —— 水题

    题目:https://www.luogu.org/problemnew/show/P1969 看每个高度和前面的关系即可. 代码如下: #include<iostream> #includ ...

  5. 搜索goog

    http://www.tech365.net/share/24.html 64.233.160.132|64.233.168.17|64.233.168.167|64.233.160.98|64.23 ...

  6. contesthunter 6201 走廊泼水节【克鲁斯卡尔+并查集】

    很有意思的题,所以还是截lyddalao的课件 #include<iostream> #include<cstdio> #include<algorithm> us ...

  7. sublime text2 配置php本地环境时遇到的错误。

    首先,将PHP加到电脑的环境变量中如图(D:\PHPEnv\PHP5是我PHP的安装目录): 第二步:添加编译系统配置 第三步:配置详情: { "cmd": ["php. ...

  8. angularjs2 不同组件间的通信

    AngualrJs2官方方法是以@Input,@Output来实现组件间的相互传值,而且组件之间必须父子关系,下面给大家提供一个简单的方法,实现组件间的传值,不仅仅是父子组件,跨模块的组件也可以实现传 ...

  9. 【杂文】C++头文件加速

    [杂文]C++头文件加速 骚年,冲钱送开挂哦,可以助你超神于OI战场 如果你发现你的暴力超时了的话,可以尝试用一下头文件加速,说不定就过了呢! #pragma once//只编译一次 #pragma ...

  10. mysql-5.7.20基本用法

    第1章 安装mysql-5.7.20 1.1 系统环境 [root@mysql ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (C ...