[POI2010]PIL-Pilots

1322439-20180330133903498-1871259224.png

【代码】

#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 3001000;
ll q_mn[N],q_mx[N],head_mx = 1,head_mn = 1, tail_mx = 0, tail_mn = 0, a[N];
ll ans = 0;
int main() {
    ll n, t, pre = 1;
    scanf("%lld%lld", &t, &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%lld",&a[i]);
        while(head_mx <= tail_mx && a[i] > a[q_mx[tail_mx]])--tail_mx;
        while(head_mn <= tail_mn && a[i] < a[q_mn[tail_mn]])--tail_mn;
        q_mx[++tail_mx] = i;
        q_mn[++tail_mn] = i;
        while(a[q_mx[head_mx]] - a[q_mn[head_mn]] > t) {
            if(q_mx[head_mx] > q_mn[head_mn]) {
                pre = q_mn[head_mn] + 1;
                ++head_mn;  
            }else {
                pre = q_mx[head_mx] + 1;
                ++head_mx;
            }
        }
        ans = max(ans, i - pre + 1);
    }
    printf("%lld\n", ans);
    return 0;
}

转载于:https://www.cnblogs.com/kcfzyhq/p/8675737.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值