zoukankan      html  css  js  c++  java
  • [POI2010]PIL-Pilots

    【代码】

    #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
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    开发日记1
    探索需求2
    探索需求1
    周总结8
    周总结7
    周总结6
    周总结5
    周总结4
    周总结3
    周总结2
  • 原文地址:https://www.cnblogs.com/kcfzyhq/p/8675737.html
Copyright © 2011-2022 走看看