头都烂了怎么头疼啊

考虑先做出对于一个位置以它作为唯一最小值的最远区间,这个可以单调栈上二分搞出来

那么对于一个位置这个区间而言,一定是选择这个区间的最大数是作为最终的唯一最大数最优的

为什么呢?我们可以把区间起止和区间之中的最大数下标弄出来,那么当前位置一定位于某两个弄出来的编号之间,其他数的答案不会大于这个区间大小,而假如是最大数除了包含这个区间以外还可以向一边拓展直到遇到下一个最大数

那么二分找出这两个编号就好了,RMQ上个st表

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector> #define qq(o,l,x) upper_bound(o+1,o+l+1,x)-o-1
using namespace std;
const int _=1e2;
const int maxn=*1e5+_;
const int fbin=;
int n,a[maxn],lslen,ls[maxn];
int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=x*+ch-'';ch=getchar();}
return x*f;
} //--------------------------------------def------------------------------------------ struct stack
{
int top,sta[maxn],d[maxn];
stack(){}
void clear(int k){top=;}
void push(int p,int x)
{
while(top>=&&d[top]>=x)top--;
sta[++top]=p;d[top]=x;
}
int findmner(int x){return sta[qq(d,top,a[x])];}
};
//~~~~~~~~stack~~~~~~~~~ int Bin[fbin],Log[maxn],f[fbin][maxn],d[fbin][maxn];
void initst()
{
Bin[]=;for(int i=;i<=;i++)Bin[i]=Bin[i-]*;
Log[]=;for(int i=;i<=n; i++)Log[i]=Log[i/]+;
for(int i=;i<=n;i++)f[][i]=a[i];
for(int j=;Bin[j]<=n;j++)
for(int i=;i+Bin[j]-<=n;i++)
f[j][i]=max(f[j-][i],f[j-][i+Bin[j-]]),
d[j][i]=max(d[j-][i],d[j-][i+Bin[j-]]);
}
int RMQ(int x,int y)
{
int k=Log[y-x+];
return max(f[k][x],f[k][y-Bin[k]+]);
}
//~~~~~~~~RMQ~~~~~~~~~~~ //--------------------------------------data structure----------------------------------------- int mnL[maxn],mnR[maxn];//作为唯一最小的区间
stack up;vector<int>vec[maxn];
int main()
{
freopen("26.in","r",stdin);
freopen("a.out","w",stdout);
n=read();
for(int i=;i<=n;i++)
a[i]=read(),ls[++lslen]=a[i];
sort(ls+,ls+lslen+);
lslen=unique(ls+,ls+lslen+)-ls-;
for(int i=;i<=n;i++)
{
a[i]=lower_bound(ls+,ls+lslen+,a[i])-ls;
vec[a[i]].push_back(i);
}
initst(); up.clear(),up.push(,-(<<));
for(int i=;i<=n;i++)
mnL[i]=up.findmner(i)+,up.push(i,a[i]);
up.clear(),up.push(n+,-(<<));
for(int i=n;i>=;i--)
mnR[i]=up.findmner(i)-,up.push(i,a[i]); int ans=,ll;
for(int i=;i<=n;i++)
{
int p=RMQ(mnL[i],mnR[i]);
if(vec[p].front()<=i)
{
int u=upper_bound(vec[p].begin(),vec[p].end(),i)-vec[p].begin()-;
int L=mnL[i],R=mnR[i];
if(u!=)L=max(L,vec[p][u-]+);
if(u!=vec[p].size()-)R=min(R,vec[p][u+]-); if(R-L+>ans || R-L+==ans&&ll>L )ans=R-L+,ll=L;
}
if(vec[p].back()>=i)
{
int u=lower_bound(vec[p].begin(),vec[p].end(),i)-vec[p].begin();
int L=mnL[i],R=mnR[i];
if(u!=)L=max(L,vec[p][u-]+);
if(u!=vec[p].size()-)R=min(R,vec[p][u+]-); if(R-L+>ans || R-L+==ans&&ll>L )ans=R-L+,ll=L;
}
}
printf("%d %d\n",ans,ll); return ;
}

bzoj4149: [AMPPZ2014]Global Warming的更多相关文章

  1. 【BZOJ4149】[AMPPZ2014]Global Warming 单调栈+RMQ+二分

    [BZOJ4149][AMPPZ2014]Global Warming Description 给定一个序列a[1],a[2],...,a[n].请从中选出一段连续子序列,使得该区间最小值唯一.最大值 ...

  2. 10324 Global Warming dfs + 二分

    时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description Global warming is a big prob ...

  3. [CEOI2018]Global warming

    [CEOI2018]Global warming 题目大意: 给定\(n(n\le2\times10^5)\),你可以将任意\(a_{l\sim r}(1\le l\le r\le n)\)每一个元素 ...

  4. BZOJ5442: [Ceoi2018]Global warming

    BZOJ5442: [Ceoi2018]Global warming https://lydsy.com/JudgeOnline/problem.php?id=5442 分析: 等价于后缀加(前缀减也 ...

  5. BZOJ 5442: [Ceoi2018]Global warming

    [l,r]+x不如[l,n]+x [l,r]-x不如(r,n)+x 所以等价于只有[l,n]+x 枚举断点树状数组合并 难度在于想到这个贪心 #include<cstdio> #inclu ...

  6. AMPPZ2014

    [AMPPZ2014]The Lawyer 记录每天结束的最早的会议以及开始的最晚的会议即可. #include<cstdio> #define N 500010 int n,m,i,d, ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. Emergency(山东省第一届ACM省赛)

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...

  9. Moscow Pre-Finals Workshop 2016. National Taiwan U Selection

    A. As Easy As Possible 每个点往右贪心找最近的点,可以得到一棵树,然后倍增查询即可. 时间复杂度$O((n+m)\log n)$. #include <bits/stdc+ ...

随机推荐

  1. localStorag的一点见解

    dot方法对localStorag方法进行键值操作 设值 localStorage.hello = 'world'; localStorage.zhangsan = 'lisi'; 取值: var v ...

  2. cmd指令

    d:  进入D盘: cd job 进入d盘名为job的文件夹:cd显示当前路径: md test创建名为test的文件夹: rd test删除名为test的文件夹: cd.>test.json创 ...

  3. 自定义table样式

    .tableWrap { width: 100%; border-collapse:collapse; border-top:1px solid #e9e9e9; border-left:1px so ...

  4. 洛谷——P2733 家的范围 Home on the Range

    P2733 家的范围 Home on the Range 题目背景 农民约翰在一片边长是N (2 <= N <= 250)英里的正方形牧场上放牧他的奶牛.(因为一些原因,他的奶牛只在正方形 ...

  5. http状态码的分类

    状态码分类 转自http://www.cnblogs.com/TankXiao/archive/2013/01/08/2818542.html HTTP状态码被分为五大类, 目前我们使用的HTTP协议 ...

  6. java集合系列之LinkedList源码分析

    java集合系列之LinkedList源码分析 LinkedList数据结构简介 LinkedList底层是通过双端双向链表实现的,其基本数据结构如下,每一个节点类为Node对象,每个Node节点包含 ...

  7. 【Java TCP/IP Socket】TCP Socket(含代码)

    TCP的Java支持 协议相当于相互通信的程序间达成的一种约定,它规定了分组报文的结构.交换方式.包含的意义以及怎样对报文所包含的信息进行解析,TCP/IP协议族有IP协议.TCP协议和UDP协议.现 ...

  8. 如何稳定地使用 Google 搜索https://encrypted.google.com/

    方法很简单.用记事本打开 hosts 文件(Windows Vista 和 Windows 7 用户请先使用管理员权限打开记事本,然后将 hosts 文件拖进记事本中),在最下面添加如下内容: 203 ...

  9. Android studio 导入githubproject

    Blog From:http://blog.csdn.net/onlysnail/article/details/45115093 从github下载两个开源项目: PagerSlidingTabSt ...

  10. GridView的经常使用属性

    1.android:numColumns="auto_fit"   //GridView的列数设置为自己主动 2.android:columnWidth="90dp &q ...