cf982d Shark

ref

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> par;
int n;
par a[100005];
set<par> se;
map<int,int> mp;
int main(){
    cin>>n;
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i].first);
        a[i].second = i;
    }
    sort(a+1, a+1+n);
    se.insert(par(1, n));
    mp[n] = 1;
    int maxn=0, ans=-1;
    for(int i=n; i; i--){
        if(mp.size()==1 && mp.begin()->second>=maxn){
            maxn = mp.begin()->second;
            ans = a[i].first + 1;
        }
        set<par>::iterator it=se.upper_bound(par(a[i].second, 0x3f3f3f3f));
        it--;
        if(it->first<=a[i].second-1){
            par x(it->first, a[i].second-1);
            se.insert(x);
            mp[x.second-x.first+1]++;
        }
        if(a[i].second+1<=it->second){
            par x(a[i].second+1, it->second);
            se.insert(x);
            mp[x.second-x.first+1]++;
        }
        int len=it->second-it->first+1;
        se.erase(it);
        mp[len]--;
        if(!mp[len])    mp.erase(len);
    }
    cout<<ans<<endl;
    return 0;
}

转载于:https://www.cnblogs.com/poorpool/p/9078721.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值