Twitter还是Amazon拿这个题目当过面试题。DP区间求面积。

 /* 1506 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 100005
#define INF 999999 int l[MAXN], r[MAXN];
__int64 a[MAXN]; __int64 max(__int64 a, __int64 b) {
return a>b ? a:b;
} int main() {
int n;
int i, j, k;
__int64 ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d",&n)!=EOF && n) {
for (i=; i<=n; ++i)
scanf("%I64d", &a[i]);
a[] = a[n+] = -INF;
l[] = ;
for (i=; i<=n; ++i) {
if (a[i-] < a[i]) {
l[i] = i;
} else {
j = i;
while (j--) {
if (a[j] < a[i]) {
l[i] = j+;
break;
} else {
j = l[j];
}
}
}
}
r[n+] = n+;
for (i=n; i>; --i) {
if (a[i+] < a[i]) {
r[i] = i;
} else {
j = i;
while (j++ <= n) {
if (a[j] < a[i]) {
r[i] = j - ;
break;
} else {
j = r[j];
}
}
}
} ans = -INF;
for (i=; i<=n; ++i) {
ans = max(ans, a[i]*(r[i]-l[i]+));
}
printf("%I64d\n", ans);
} return ;
}

最新文章

  1. 前端ps常用的小技巧
  2. markdown语法书
  3. js script中引用其他script
  4. http学习笔记(四)——HTTP报文
  5. web开发workflow
  6. 一个介绍webrtc的国外网址
  7. Lambda(2)
  8. Linux中ifreq 结构体分析和使用 及其在项目中的简单应用
  9. SQL 添加字段和默认值脚本
  10. html动态编辑框
  11. 快速构建Windows 8风格应用2-创建调试应用
  12. OpenCV探索之路(二十八):Bag of Features(BoF)图像分类实践
  13. poj1699
  14. 如何让html中的td文字只显示部分
  15. python就业班-淘宝-目录.txt
  16. unity3d-绘制贴图
  17. PIVOT函数与UNPIVOT函数的运用
  18. Linux嵌入式内核模块程序设计
  19. Java50道经典习题-程序6 求最大公约数及最小公倍数
  20. ORA-10485: Real-Time Query cannot be enabled while applying migration redo

热门文章

  1. PHP自学之路---报表及绘图技术
  2. umlの用例图
  3. iOS 开发-单元测试
  4. HUD2087
  5. 移动页面缩放方法之(一)控制meta法
  6. java 跳转地址栏地址改变
  7. KMP算法总结
  8. linux command cp.
  9. SQL In的替换
  10. 学会用Clang来进行内存泄露分析