头都烂了怎么头疼啊

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

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

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

那么二分找出这两个编号就好了,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. 转载:shell中awk printf的用法

    转载:http://www.linuxawk.com/jiaocheng/83.html 6. printf函数   打印输出时,可能需要指定字段间的空格数,从而把列排整齐.在print函数中使用制表 ...

  2. Vmware error:无法获得 VMCI 驱动程序的版本: 句柄无效。

    error:无法获得 VMCI 驱动程序的版本: 句柄无效.驱动程序“vmci.sys”的版本不正确.请尝试重新安装 VMware Workstation.开启模块 DevicePowerOn 的操作 ...

  3. Spoj-BGSHOOT

    The problem is about Mr.BG who is a great hunter. Today he has gone to a dense forest for hunting an ...

  4. BSGS算法 (小步大步 Baby Step Gaint Step)

    当你要求满足: $$ A^x \equiv B \ (\bmod \ P) $$ 的最小非负整数 x (gcd(A,P)==1)就可以用到 BSGS 了 设 $ m=\sqrt{P} $ 向上取整 处 ...

  5. 生日聚会 BZOJ 1037

    生日聚会 [问题描述] 今天是hidadz小朋友的生日,她邀请了许多朋友来参加她的生日party. hidadz带着朋友们来到花园中,打算坐成一排玩游戏.为了游戏不至于无聊,就座的方案应满足如下条件: ...

  6. dbms_metadata.get_ddl的使用总结

    https://blog.csdn.net/newhappy2008/article/details/34823339

  7. wc递归统计代码行数

    find /path -name '*.cpp' |xargs wc -l

  8. chrome插件网站

    chrome插件网站 http://chromecj.com/

  9. 在Nginx上部署ThinkPHP,解决Pathinfo问题

    在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...

  10. svn 创建分支、切换分支 及 合并分支 操作

    关联远程仓库: 右键  ---  点击 ' SVN Checkout...' 生成 打开trunk目录,在trunk目录下新建两个文本文件A.java,B.java: 打开A.java输入以下内容: ...