题意

题目链接

Sol

很神仙的题目啊,考场上只会$n^2$的暴力。。

考虑直接二分一个$mid$,我们来判断最终答案是否可能大于$x$。

判断的时候记录一下前缀最小值即可,

设$s[i]$表示$1-i$中有多少比它大的,要求的长度为$len$,我们记下$s[i - len]$的最小值为$Mi$

若$s[i] - Mi > 0$,那么说明在长度至少为$len$的区间中,大于$mid$的数和小于$mid$的数相互抵消后仍然有比$mid$大的数,此时$mid$是合法的

第一次做这种二分答案,但答案不是给出的数的题。神仙啊qwq

/*

*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#include<set>
#include<vector>
//#define int long long
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 1e5 + , INF = 1e9 + , mod = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, len, s[MAXN], a[MAXN];
int check(int x) {
for(int i = ; i <= N; i++)
if(a[i] < x) s[i] = -;
else s[i] = ;//s[i] : 1 - i中有多少比x大的
int Mi = ;
for(int i = ; i <= N; i++) {
s[i] += s[i - ];
if(i >= len) Mi = min(Mi, s[i - len]);
if(i >= len && (s[i] - Mi > )) return ;
}
return ;
}
int main() {
// freopen("a.in", "r", stdin);
// freopen("c.out", "w", stdout);
N = read(); len = read();
for(int i = ; i <= N; i++) a[i] = read();
int l = , r = 1e9 + , ans;
while(l <= r) {
int mid = l + r >> ;
if(check(mid)) ans = mid, l = mid + ;//是否有比mid大的解
else r = mid - ;
}
printf("%d", ans);
return ;
}
/*
5 4
7 2 3 2 6
*/

最新文章

  1. android多线程断点续传下载文件
  2. Use Visual studio 2010 build Python2.7.10
  3. ERROR: “System.Web.Mvc.Controller.File(string, string, string)”是一个“方法”
  4. service mysql start出错,mysql启动不了,解决mysql: unrecognized service错误
  5. PHP删除MySQL数据库下的所有数据表
  6. 对页面制定区域进行打印,以及打印不显示页脚URL的方法
  7. 有关javascript中的JSON.parse和JSON.stringify的使用一二
  8. Android AlertDialog 设置setSingleChoiceItems不显示列表的原因【setMessage和setSingleChoiceItems不能同时使用】
  9. IOS-objectForKey与valueForKey在NSDictionary中的差异
  10. ckeditor3.4.2是否升级为4.2.1的问题
  11. 一个网友写的栈,问为啥不能迭代。具有__iter__ 和next方法的对象叫迭代器-七七巴巴黄页网
  12. mousewheel 与 DOMMouseScroll
  13. 怎么去理解JAVA中类与对象的关系
  14. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之六 || API项目整体搭建 6.1 仓储模式
  15. 阿里云服务器Ubuntu 14.04.2和centos7.5实现nfs挂载
  16. Kettle解决方案: 第五章 ETL相关知识
  17. applicationContext.xml 模板
  18. topcoder srm 704 div1
  19. python3.4学习笔记(二十一) python实现指定字符串补全空格、前面填充0的方法
  20. HDU 6130 Kolakoski

热门文章

  1. screen命令常用参数使用
  2. 【aspnetcore】配置使用jwt验证
  3. vue——做了一个幼稚的小页面
  4. JAVA多线程之线程池的使用
  5. Asp.NetCore 从控制台到WebApi
  6. HTTPS和SSL证书
  7. volatile底层原理详解
  8. elasticsearch报错:None of the configured nodes are available: []
  9. Atcoder训练计划
  10. python起源,变量,用户交互,流程语句