【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

用单调队列求出l[i]和r[i]
分别表示i的左边最近的大于a[i]的数的位置以及i右边最近的大于a[i]的数的位置。
则l[i]+1..r[i]-1就是a[i]这个数作为最小数的最大管辖区间了。
写个前缀和就好。

然后取a[i]*区间l[i]+1..r[i]-1的和 中的最大值。

并不是special judge

多个相同区间。

取区间长度最短的区间。

如果仍有多个答案。

取左端点最小的那个区间。

(全都是0的情况要注意,直接取[1,1]就好,不能取[1..n]

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 1e5; int n,a[N+10],l[N+10],r[N+10];
LL pre[N+10];
stack<int> sta; void solve(){
rep1(i,1,n) cin >> a[i];
pre[0] = 0;
rep1(i,1,n) pre[i] = pre[i-1]+a[i];
l[1] = 0; while (!sta.empty()) sta.pop(); sta.push(1);
for (int i = 2;i <= n;i++){
while (!sta.empty() && a[sta.top()]>=a[i]) sta.pop();
if (sta.empty())
l[i] = 0;
else
l[i] = sta.top();
sta.push(i);
} while (!sta.empty()) sta.pop();
sta.push(n);
r[n] = n+1;
for (int i = n-1;i >= 1;i--){
while (!sta.empty() && a[sta.top()]>=a[i]) sta.pop();
if (sta.empty())
r[i] = n+1;
else
r[i] = sta.top();
sta.push(i);
} long long ans = -1;
int posl,posr; rep1(i,1,n){
int ll = l[i]+1;int rr = r[i]-1;
if (a[ll]==0 && a[rr]==0){
rr = ll;
}
LL temp = 1LL*a[i]*(pre[rr]-pre[ll-1]); if (temp>ans){
ans = temp;
posl = ll,posr = rr;
}else if (temp==ans){
if (posr-posl>rr-ll || (posr-posl==rr-ll && ll<posl)){
posl = ll,posr = rr;
}
}
}
cout<<ans<<endl;
cout<<posl<<' '<<posr<<endl;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin>>n){
if (kase>0)
cout<<endl;
else
kase++;
solve();
}
return 0;
}

【习题 8-18 UVA - 1619】Feel Good的更多相关文章

  1. UVA 1619 Feel Good(DP)

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

  2. POJ 2796[UVA 1619] Feel Good

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

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

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

  4. [UVa 1619]Feel Good

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

  5. Java50道经典习题-程序18 乒乓球赛

    题目:两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单. a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单.分析: ...

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

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

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

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

  8. UVA - 1619 Feel Good(扫描法)

    题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/st ...

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

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

随机推荐

  1. hiho1041 - 树,遍历

    题目链接 给一棵树,给一个序列,问能不能按这个序列遍历这棵树,满足每条边最多经过两次. -------------------------------------------------------- ...

  2. pthread_cleanup_push vs Autorelease VS 异常处理

    黑幕背后的Autorelease http://www.cnblogs.com/feng9exe/p/7239552.html objc_autoreleasePoolPush的返回值正是这个哨兵对象 ...

  3. SpringCloud学习笔记(12)----Spring Cloud Netflix之Hystrix断路器的流程和原理

    工作流程(参考:https://github.com/Netflix/Hystrix/wiki/How-it-Works) 1. 创建一个HystrixCommand或HystrixObservabl ...

  4. OSI参考模型概论

  5. (WC2016模拟十八)【BZOJ4299】[CodeChef]FRBSUM

    咕了若干天我终于来补坑了qwq HINT $1\leq N,M\leq 10^5$ $1\leq \sum A_i\leq 10^9$ 题解: 虽然场上做出来了但还是觉得好神啊! 假设当前集合能凑出$ ...

  6. 浅谈python 中正则的一些函数

         主要的函数有  : match() search() findall() group() groups() split()  match (): 含义  开头匹配,匹配成功返回一个对象失败则 ...

  7. pandas 4 处理缺失数据nan

    from __future__ import print_function import pandas as pd import numpy as np np.random.seed(1) dates ...

  8. Eclipse WEB项目更改项目名

    可能很多人都碰到过 WEB 项目需要改名字的事情,不过不是每个人都能很顺畅地完成这个事情.这里简单给大家介绍两种改项目名的方法 1. 在Eclipse 中修改项目名 没错这种方法跟你预料的一样简单,当 ...

  9. android开发之Animation(五)

    android开发之Animation的使用(五) 本博文主要讲述的是Animation中的AnimationLisenter的用法,以及此类的一些生命周期函数的调用,代码实比例如以下: MainAc ...

  10. Android组件系列----ContentProvider内容提供者【1】

    [正文] 一.ContentProvider简单介绍: ContentProvider内容提供者(四大组件之中的一个)主要用于在不同的应用程序之间实现数据共享的功能. ContentProvider能 ...