题目:

思路:

预处理出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. sql 查询如何将结果集 输出为一段字符串?

    文件id集合 文件表. SELECT CONCAT('2323',(SELECT 'dsfsd'),'232323'); SELECT CONCAT('2323',(SELECT file_ids F ...

  2. ABAP OLE

    OLE DATA: excel TYPE ole2_object, workbook TYPE ole2_object, sheet TYPE ole2_object, cell TYPE ole2_ ...

  3. [RK3288][Android6.0] 调试笔记 --- 录音音量从HAL到APP层会变小问题【转】

    本文转载自:http://blog.csdn.net/kris_fei/article/details/72783843?locationNum=9&fps=1 Platform: Rockc ...

  4. 【Poj3126】【BNUOJ3245】Prime Path

    http://poj.org/problem?id=3126 https://www.bnuoj.com/v3/problem_show.php?pid=3245 题目鬼图 刚开始看到题目的图觉得这题 ...

  5. bzoj 4883 棋盘上的守卫 —— 基环树转化

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4883 首先,注意到每个点可横可竖,但花费一样: 所以考虑行列的交集,那么这个条件可以转化为行 ...

  6. bzoj4237 稻草人——分治

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4237 分治: 先把所有点按 y 排序,然后二分递归: 对于每个 mid ,计算经过它的矩形的 ...

  7. uva10828

    https://vjudge.net/problem/UVA-10828 裸高斯消元... 但是要判无解和无穷解. 当出现一个环时会无解,环上每个点只有一个出边. #include<bits/s ...

  8. 服务器端解决ajax跨域问题

    这里描述以Tomcat为Web服务器情况下的解决办法,在Java Web程序的WEB-INF下的web.xml文件中加入如下配置即可. <!--cors filter--> <fil ...

  9. Linux的文件搜索命令(locate ,find,grep,find命令和)

    刚开始学Linux,这是关于Linux文件搜索命令,就目前,尽我所能把他写全一点,后期随时补充 文件搜索命令 一.locate命令 二.find命令 三.grep命令 四.find命令和grep命令的 ...

  10. 如何快速删除Linux下的svn隐藏文件及其他临时文件 (转载)

    转自:http://blog.csdn.net/edsam49/article/details/5840489 在Linux下,你的代码工程如果是用svn进行管理的,要删除Linux kernel里的 ...