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

【题意】

在这里输入题意

【题解】

用单调队列求出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]

【代码】

  1. #include <bits/stdc++.h>
  2. #define LL long long
  3. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  4. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  5. #define all(x) x.begin(),x.end()
  6. #define pb push_back
  7. #define ls l,mid,rt<<1
  8. #define rs mid+1,r,rt<<1
  9. using namespace std;
  10. const double pi = acos(-1);
  11. const int dx[4] = {0,0,1,-1};
  12. const int dy[4] = {1,-1,0,0};
  13. const int N = 1e5;
  14. int n,a[N+10],l[N+10],r[N+10];
  15. LL pre[N+10];
  16. stack<int> sta;
  17. void solve(){
  18. rep1(i,1,n) cin >> a[i];
  19. pre[0] = 0;
  20. rep1(i,1,n) pre[i] = pre[i-1]+a[i];
  21. l[1] = 0;
  22. while (!sta.empty()) sta.pop();
  23. sta.push(1);
  24. for (int i = 2;i <= n;i++){
  25. while (!sta.empty() && a[sta.top()]>=a[i]) sta.pop();
  26. if (sta.empty())
  27. l[i] = 0;
  28. else
  29. l[i] = sta.top();
  30. sta.push(i);
  31. }
  32. while (!sta.empty()) sta.pop();
  33. sta.push(n);
  34. r[n] = n+1;
  35. for (int i = n-1;i >= 1;i--){
  36. while (!sta.empty() && a[sta.top()]>=a[i]) sta.pop();
  37. if (sta.empty())
  38. r[i] = n+1;
  39. else
  40. r[i] = sta.top();
  41. sta.push(i);
  42. }
  43. long long ans = -1;
  44. int posl,posr;
  45. rep1(i,1,n){
  46. int ll = l[i]+1;int rr = r[i]-1;
  47. if (a[ll]==0 && a[rr]==0){
  48. rr = ll;
  49. }
  50. LL temp = 1LL*a[i]*(pre[rr]-pre[ll-1]);
  51. if (temp>ans){
  52. ans = temp;
  53. posl = ll,posr = rr;
  54. }else if (temp==ans){
  55. if (posr-posl>rr-ll || (posr-posl==rr-ll && ll<posl)){
  56. posl = ll,posr = rr;
  57. }
  58. }
  59. }
  60. cout<<ans<<endl;
  61. cout<<posl<<' '<<posr<<endl;
  62. }
  63. int main(){
  64. #ifdef LOCAL_DEFINE
  65. freopen("rush_in.txt", "r", stdin);
  66. #endif
  67. ios::sync_with_stdio(0),cin.tie(0);
  68. int kase = 0;
  69. while (cin>>n){
  70. if (kase>0)
  71. cout<<endl;
  72. else
  73. kase++;
  74. solve();
  75. }
  76. return 0;
  77. }

【习题 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. 前端学习之路——gulp篇

    一.构建gulp环境 1.下载nodejs gulp基于node.js,要通过nodejs的npm安装gulp,所以要先安装node.js环境.(英文官网/中文官网链接). 通过cmd命令窗口确定安装 ...

  2. SpringCloud学习笔记(8)----Spring Cloud Netflix之负载均衡-Ribbon的负载均衡的策略

    一. 内置 负载均衡策略的介绍的 IRule的实现类 2. 通过代码实现负载均衡 在第六节Riddom的使用的工程中,随机策略配置类 package com.wangx.cloud.springclo ...

  3. 洛谷 P3203 [HNOI2010]弹飞绵羊 分块

    我们只需将序列分成 n\sqrt{n}n​ 块,对于每一个点维护一个 val[i]val[i]val[i],to[i]to[i]to[i],分别代表该点跳到下一个块所需要的代价以及会跳到的节点编号.在 ...

  4. vue的表格加单选框

    https://www.cnblogs.com/calamus/p/8569196.html

  5. 利用js自带函数 数组去重

    <script> ,,]; //原数组 var a=[]; //定义空数组 arr.map(function(x){ //用 map 遍历数组 ){ //如果当前值没有存在空数组中 a.p ...

  6. du -sh*查看当前目录下的文件夹大小

    du -sh*查看当前目录下的文件夹大小   u 命令    用途    概述磁盘使用.    语法  du [ -a | -s ] [ -k ] [ -m ] [ -g ][ -l ] [ -r ] ...

  7. tar 命令man说明

    TAR(1) User Commands TAR(1) NAME tar - manual page for tar 1.26 SYNOPSIS tar [OPTION...] [FILE]... D ...

  8. 关于数组array_diff(array1, array2)求差集来比较数组是否相等的问题细究

    无意中发现很多朋友都喜欢使用array_diff(array1, array2)来判断两个数组是否相等, 我自己也偶尔会这么使用 但是今天我在写代码的过程中无意发现这么做是不准确的. 首先我们来看一下 ...

  9. C语言修改文件某部分内容

    两种方法 1.全部读入内存 修改后重新存入文件 2.边读边写到另一新建文件 要修改的部分修改后存入新建文件 其他部分原封不动写入 写完删掉原先文件 将这个新的改为删掉那个的名字 方法一 读入内存修改 ...

  10. Ubuntu 10.04 右上角网络管理图标消失的解决的方法

           那个显示网络状态的那个图标.叫做:network-manager.假设是有线网络连接的话.是上下两个箭头,假设是无线网络的话.是一个发射信号的形状. sudo gedit /etc/Ne ...