HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分
分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可
找第一个点可以二分可以尺取
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 2e5+;
int T,n,m,k,a[N],sum[N];
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;++i){
scanf("%d",&a[i]);
if(a[i]>=m)a[i]=;
else a[i]=;
}
for(int i=;i<=n;++i)sum[i]=sum[i-]+a[i];
LL ret=;
for(int i=;i<=n;++i){
if(n-i+<k)break;
if(sum[n]-sum[i-]<k)break;
int l=i+k-,r=n;
while(l<r){
int mid=(l+r)>>;
if(sum[mid]-sum[i-]>=k)r=mid;
else l=mid+;
}
int tmp=(l+r)>>;
ret+=(n-tmp+);
}
printf("%I64d\n",ret);
}
return ;
}
HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分的更多相关文章
- HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理
分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍 #include <cstdio> #include <cstring> #include <cmath> ...
- HDU5806 NanoApe Loves Sequence Ⅱ
NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Ja ...
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/13107 ...
- HDU-5806 NanoApe Loves Sequence Ⅱ(two-pointer或二分)
题目大意:给一个整数序列,统计<k,m>子序列的数目.<k,m>序列是满足第k大的数字不比m小的连续子序列. 题目分析:维护一个不小于m的数的个数的后缀和数组,可以枚举序列起点 ...
- Best Coder #86 1002 NanoApe Loves Sequence
NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 5806 NanoApe Loves Sequence Ⅱ(尺取法)
传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K ...
- 5805 NanoApe Loves Sequence(想法题)
传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K ( ...
- BestCoder Round #86
A题 Price List 巨水..........水的不敢相信. #include <cstdio> typedef long long LL; int main() { int T; ...
- BestCoder Round #86 解题报告
A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...
随机推荐
- My SQL InnoDB 1217 - Cannot delete or update a parent row:aforeign key constraint fals
InnoDB 允许有外键 MyISAM 不允许有外键 InnoDB修改成MyISAM 证明有外键 一张表如果有其他表的外键关联的是它 它也不能是MyISAM 来自为知笔记(Wiz)
- JavaWeb笔记——三大组件之监听器
1 JavaWeb监听器概述 在JavaWeb被监听的事件源为:ServletContext.HttpSession.ServletRequest,即三大域对象. l 监听域对象“创建”与“销毁”的 ...
- 296. Best Meeting Point
题目: A group of two or more people wants to meet and minimize the total travel distance. You are give ...
- Win XP 如何禁用屏保
如果你试过 “在桌面空白处点击右键-[属性]-[屏幕保护程序],选择[无],点击[确定]”后,当时是可以去掉屏保.但如果重启计算机或者从待机状态唤醒后,屏保依然会出现,那么你可以试试下面的方法. 首先 ...
- 如何设置 Windows 开机启动项
点击[开始]-[运行](或者使用快捷键-Win + R),输入 msconfig
- Python得到两个时间段的每一天的列表
date_list = [] begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d") end_date = ...
- python3字符串格式化
print('Hello World')print('%s',55)print('%6.2f' % 1.235)print('%06.2f' % 1.235)print('-%06.2f' % 1.2 ...
- [HDOJ5584]LCM Walk(数论,规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5584 给一个坐标(ex, ey),问是由哪几个点走过来的.走的规则是x或者y加上他们的最小公倍数lcm ...
- leetcode:Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1即反转二叉树,代码如下: /** * Defin ...
- hdu 5718 Oracle 高精度
Oracle Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Problem ...