zoukankan      html  css  js  c++  java
  • Luogu3594 [POI2015]WIL-Wilcze doły (双端队列)

    单调性显然,双端队列队列维护严格单调递减手写双端队列真的可恶

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    //#include <queue>
    
    const int N = 2000007;
    
    int a[N];
    long long sum[N], x[N];
    //deque<int> q;
    int q[N], t, h = 1;
    int main(){
    //FileOpen();
    	int n, d;
    	long long Val;
    	io >> n >> Val >> d; 
        R(i,1,n){
        	io >> a[i];
        	sum[i] = sum[i - 1] + a[i];
        }
       	R(i,d,n){
       		x[i] = sum[i] - sum[i - d];
       	} 
    	int ans = d;
    	q[++t] = d;
    	int l = 1;
    	R(r,d,n){
    		while(h <= t && x[r] >= x[q[t]]) --t;
    		q[++t] = r;
    		while(h <= t && q[h] - d + 1< l) ++h;
    		while(h <= t && sum[r] - sum[l - 1] - x[q[h]] > Val){
    			++l;
    			while(h <= t && q[h] - d + 1 < l) ++h;
    		}
    		ans = Max(ans, r - l + 1);
    	}
        printf("%d", ans);
        return 0;
    }
    

  • 相关阅读:
    列表解析、字典解析、集合解析、生成器解析
    匿名函数lambda
    一、软件开发的常识
    Vocabulary Recitation 2020/04/26
    Vocabulary Recitation 2020/04/25
    Vocabulary Recitation 2020/04/24
    数据结构_郝斌_五种常用排序概述
    Vocabulary Recitation 2020/04/23
    Vocabulary Recitation 2020/04/22
    数据结构_郝斌_树与图
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11253990.html
Copyright © 2011-2022 走看看