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

【题意】

在这里输入题意

【题解】

用单调队列求出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. LeetCode 744. Find Smallest Letter Greater Than Target (时间复杂度O(n))

    题目 太简单了,直接上代码: class Solution { public: char nextGreatestLetter(vector<char>& letters, cha ...

  2. HDU 1087 Super Jumping! Jumping! Jumping!【DP】

    解题思路:题目的大意是给出一列数,求这列数里面最长递增数列的和 dp[i]表示到达地点i的最大值,那么是如何达到i的呢,则我们可以考虑没有限制条件时候的跳跃,即可以从第1,2,3,---,i-1个地点 ...

  3. 搭健MyBatis开发环境

    相关文献资料地址:http://www.mybatis.org/mybatis-3/zh/getting-started.html 关于如何创建一个项目,添加Tomcat运行环境和生成`web.xml ...

  4. 洛谷 P4932 浏览器 (思维题)

    题目大意:给你一个序列,求满足$x_{i}\: xor\; x_{j}$在二进制下1的数量为奇数的数对数量 打月赛的时候真没想出来,还是我太弱.. xor意义下,对于两个数,假设它们两个每一位都是2个 ...

  5. centos7.x86_64搭建饥荒服务器

    http://blog.ttionya.com/article-1233.html 在centos7下找不到 libcurl-gnutls.so.4,而且必须要安装32位的才行 yum install ...

  6. [MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change

    n this lesson, we will set up Hot Module Reloading(HMR), making it possible to load new definitions ...

  7. [Angular] Configure an Angular App at Runtime

    It always again happens (especially in real world scenarios) that you need to configure your Angular ...

  8. HDU 5310 Souvenir

    Souvenir  Accepts: 901  Submissions: 2743  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 262 ...

  9. android开发之Animation(五)

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

  10. poj_3468,线段树成段更新

    参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #include& ...