BZOJ 4385 洛谷3594 POI2015 WIL-Wilcze doły

【题解】
手残写错调了好久QAQ......
洛谷的数据似乎比较水。。
n个正整数!!这很重要
这道题是个类似two pointer的思想,外加一个单调队列维护当前区间内长度为d的子序列中元素之和的最大值。
枚举右端点,如果左端点到右端点的元素和减去区间内长为d的子序列中元素和的最大值,大于给定的P,那么就把左端点向右挪。
#include<cstdio>
#include<algorithm>
#define N 2000010
#define rg register
#define LL long long
using namespace std;
LL n,m,d,a[N],h[N],s[N],p[N],tmp;
int ans;
inline LL read(){
LL k=0; char c=getchar();
while(c<'0'||c>'9')c=getchar();
while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
return k;
}
inline int max(int x,int y){
return x>y?x:y;
}
int main(){
n=read(); m=read(); ans=d=read();
for(rg int i=1;i<=n;i++) a[i]=read(),s[i]=s[i-1]+a[i];
if(n<=d) return printf("%d\n",d),0;
int l=1,front=1,rear=0;
for(rg int i=d+1;i<=n;i++){
tmp=s[i]-s[i-d];
while(front<=rear&&h[rear]<=tmp) rear--;
h[++rear]=tmp; p[rear]=i-d+1;
while(p[front]<l&&front<=rear) front++;
while(l<=i-d+1){
if(front<=rear) tmp=s[i]-s[l-1]-h[front];
else tmp=s[i]-s[l-1];
if(tmp<=m){
ans=max(ans,i-l+1);
break;
}
else l++;
}
tmp=s[i]-s[l-1];
}
printf("%d\n",ans);
return 0;
}
BZOJ 4385 洛谷3594 POI2015 WIL-Wilcze doły的更多相关文章
- BZOJ 3747 洛谷 3582 [POI2015]Kinoman
[题解] 扫描线+线段树. 我们记第i部电影上次出现的位置是$pre[i]$,我们从$1$到$n$扫描,每次区间$(pre[i],i]$加上第i部电影的贡献$w[f[i]]$,区间$[pre[pre[ ...
- [BZOJ 3039&洛谷P4147]玉蟾宫 题解(单调栈)
[BZOJ 3039&洛谷P4147]玉蟾宫 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. ...
- bzoj 4816: 洛谷 P3704: [SDOI2017]数字表格
洛谷很早以前就写过了,今天交到bzoj发现TLE了. 检查了一下发现自己复杂度是错的. 题目传送门:洛谷P3704. 题意简述: 求 \(\prod_{i=1}^{N}\prod_{j=1}^{M}F ...
- bzoj 1014: 洛谷 P4036: [JSOI2008]火星人
题目传送门:洛谷P4036. 题意简述: 有一个字符串,支持插入字符,修改字符. 每次需要查询两个后缀的LCP长度. 最终字符串长度\(\le 100,\!000\),修改和询问的总个数\(\le 1 ...
- bzoj 3680(洛谷1337) 吊打XXX——模拟退火
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3680 https://www.luogu.org/problemnew/show/P1337 ...
- bzoj 4592(洛谷 4344) [Shoi2015]脑洞治疗仪——线段树上二分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4592 1操作就是用线段树来二分找到第一个有 k 个0的位置. 在洛谷上A了,与暴力和网上题解 ...
- Guard Duty (medium) Codeforces - 958E2 || (bzoj 2151||洛谷P1792) 种树 || 编译优化
https://codeforces.com/contest/958/problem/E2 首先求出N个时刻的N-1个间隔长度,问题就相当于在这些间隔中选K个数,相邻两个不能同时选,要求和最小 方法1 ...
- bzoj 2005 & 洛谷 P1447 [ Noi 2010 ] 能量采集 —— 容斥 / 莫比乌斯反演
题目:bzoj 2005 https://www.lydsy.com/JudgeOnline/problem.php?id=2005 洛谷 P1447 https://www.luogu.org/ ...
- BZOJ 1901 洛谷 P2617 ZOJ 2112 Dynamic Rankings
以下时空限制来自zoj Time limit 10000 ms Memory limit 32768 kB OS Linux Source Online Contest of Christopher' ...
随机推荐
- jquery easyui 显示和关闭数据加载的遮罩
$('#yearReportTable').datagrid('loading');//打开等待div $('#yearReportTable').datagrid('loaded');//关闭等待d ...
- sql清空表数据后重新添加数据存储过程
ALTER PROCEDURE [dbo].[sp_add_Jurisdiction] @CTableName varchar(20), --当前要删除.新增的表 @filedkeyValue var ...
- bzoj 1754: [Usaco2005 qua]Bull Math【高精乘法】
高精乘法板子 然而WA了两次也是没救了 #include<iostream> #include<cstdio> #include<cstring> using na ...
- 17年day4
/* 嗯,又一天 上午考试,睡了两觉(我不会把我第二觉流了口水这件事说出去) 状态比较玄学,上午困得要死,下午无比精神(感觉NOIP要完). 复习了概率期望.发现以前做过的题还是不会做,好像连印象都比 ...
- 使用nginx加zuul配置
配置文件 $ ls -lrt -rw-r--r-- 1 root root 826 May 10 10:56 nginx.conf $ pwd /etc/nginx 增加配置 在http {}里 up ...
- php 文件上传限制修改
修改PHP上传文件大小限制的方法 1. 一般的文件上传,除非文件很小.就像一个5M的文件,很可能要超过一分钟才能上传完.但在php中,默认的该页最久执行时间为 30 秒.就是说超过30秒,该脚本就停止 ...
- MongoDB Built-In Roles(内置角色)
1. 数据库用户角色:read.readWrite; 2. 数据库管理角色:dbAdmin.dbOwner.userAdmin: 3. 集群管理角色:clusterAdmin.clusterManag ...
- DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
- SpringMVC实现Action的两种方式以及与Struts2的区别
4.程序员写的Action可采用哪两种方式? 第一.实现Controller接口第二.继承自AbstractCommandController接口 5.springmvc与struts2的区别? 第一 ...
- ora-20000 unable to analyze
ora-20000 unable to analyze 无法分析表 check: select * from wmsprdata.cmp3$88278表不存在. result:应该是系统自动任务2:0 ...