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;
    }
    

  • 相关阅读:
    Linux常用的命令
    【练习】分区
    【测试】RAC搭建(裸设备)
    【练习】使用事务和锁定语句
    【练习】使用事务控制语句
    【练习】设置数据类型
    【练习】显示MySQLadmin 库户籍选项
    【练习】显示MYSQL客户机选项
    【练习】如何显示本地主机上的MySQL客户机版本
    【测试】切换保护模式,最大性能到最大可用
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11253990.html
Copyright © 2011-2022 走看看