poj 2796
来源:互联网 发布:oracle数据库基本语句 编辑:程序博客网 时间:2024/06/05 06:21
如果确定了
因为序列中所有数的值非负,所以只需要考虑满足以上条件的最长区间即可。
而包含
#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <string>#include <map>#include <vector>#include <stack>#include <queue>#include <utility>#include <iostream>#include <algorithm>template<class Num>void read(Num &x){ char c; int flag = 1; while((c = getchar()) < '0' || c > '9') if(c == '-') flag *= -1; x = c - '0'; while((c = getchar()) >= '0' && c <= '9') x = (x<<3) + (x<<1) + (c-'0'); x *= flag; return;}template<class Num>void write(Num x){ if(x < 0) putchar('-'), x = -x; static char s[20];int sl = 0; while(x) s[sl++] = x%10 + '0',x /= 10; if(!sl) {putchar('0');return;} while(sl) putchar(s[--sl]);}#define REP(__i,__st,__ed) for(int __i = (__st); __i <= (__ed); __i++)#define _REP(__i,__st,__ed) for(int __i = (__st); __i >= (__ed); __i--)const int maxn = 1e5 + 50;int n, a[maxn], pre[maxn], sur[maxn];int stack[maxn], top;long long ans, sum[maxn];int ansl, ansr;void init(){ read(n); REP(i, 1, n) read(a[i]);}void prework(){ REP(i, 1, n) sum[i] = sum[i - 1] + a[i]; REP(i, 1, n) { while(top && a[i] <= a[stack[top]]) stack[top--] = 0; pre[i] = (top?stack[top]:0) + 1, stack[++top] = i; } top = 0; _REP(i, n, 1) { while(top && a[i] <= a[stack[top]]) stack[top--] = 0; sur[i] = (top?stack[top]:(n + 1)) - 1, stack[++top] = i; }}void solve(){ ans = a[1], ansl = ansr = 1; REP(i, 1, n) { long long calc = (sum[sur[i]] - sum[pre[i] - 1])*a[i]; if(calc > ans) ans = calc, ansl = pre[i], ansr = sur[i]; } write(ans), puts(""); write(ansl), putchar(' '), write(ansr);}int main(){#ifndef ONLINE_JUDGE freopen("2796.in","r",stdin); freopen("2796.out","w",stdout);#endif init(); prework(); solve();#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0; }
0 0
- POJ 2796
- poj 2796
- poj 2796
- POJ 2796
- poj 2796
- poj 2796
- poj 2796
- poj 2796 数字求和
- poj 2796 Feel Good
- poj 2796#单调栈
- POJ 2796 Feel Good
- POJ 2796 Feel Good
- poj 2796 Feel Good
- poj 2796 feel good
- POJ 2796 单调栈~
- POJ-2796-Feel Good
- POJ 2796Feel Good
- poj 2796 Feel Good
- hunnu OJ 11567 Escaping(拆点型最大匹配/网络流)
- 【细说PHP学习】第十一章 字符串处理
- Spring监听器与proxool.xml(数据库连接池)
- Android典型界面设计(5)——使用SlidingMenu和DrawerLayout分别实现左右侧边栏
- IDW插值服务
- poj 2796
- objective-C中没有"接口"与"泛型"这样的说法,但有正式协议protocal 和 一种特殊的指针id类型
- Solr Cache使用介绍及分析
- 利用 gnuplot 绘制时间序列图 http://blog.csdn.net/liyuanbhu/article/details/8497582
- JPA对应的数据库字段大小写问题
- Android Studio写Android代码时Java文件实现Eclipse包浏览效果
- poj 2774 Long Long Message 后缀数组
- hdu 5364 Distribution money 简单题
- asp.net中AngularJS+ashx的使用