NanoApe Loves Sequence Ⅱ

 Accepts: 374
 Submissions: 946
 Time Limit: 4000/2000 MS (Java/Others)
 Memory Limit: 262144/131072 K (Java/Others)
问题描述
退役狗 NanoApe 滚回去学文化课啦!

在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 nn 的数列,他又根据心情写下了一个数 mm。

他想知道这个数列中有多少个区间里的第 kk 大的数不小于 mm,当然首先这个区间必须至少要有 kk 个数啦。
输入描述
第一行为一个正整数 TT,表示数据组数。

每组数据的第一行为三个整数 nmkn,m,k。

第二行为 nn 个整数 AiA​i​​,表示这个数列。

1T10 2n200000 1kn/2 1mAi1091≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,A​i​​≤10​9​​
输出描述
对于每组数据输出一行一个数表示答案。
输入样例
1
7 4 2
4 2 7 7 6 5 1
输出样例
18

才知道原来有two-pointer这个名字

>=m的数为1,其他为0,那么就是求有多少个区间和>=k

滑动窗口,i是头,p是尾

//
// main.cpp
// bc86-1003
//
// Created by Candy on 10/1/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
const int N=2e5+;
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;
}
int T,n,m,k,a[N];
int main(int argc, const char * argv[]) {
T=read();
while(T--){
n=read();m=read();k=read();
for(int i=;i<=n;i++){a[i]=read();a[i]=a[i]>=m?:;}
int cnt=,p=;
long long ans=;
for(int i=;i<=n-k+;i++){
while(cnt<k&&p<=n)
cnt+=a[p++];
if(cnt>=k) ans+=(long long)(n-p++);//p already add 1
cnt-=a[i];
}
printf("%lld\n",ans);
} return ;
}

BC#86 1003NanoApe Loves Sequence Ⅱ[two-pointer]的更多相关文章

  1. Best Coder #86 1002 NanoApe Loves Sequence

    NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...

  2. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

  3. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  4. 5806 NanoApe Loves Sequence Ⅱ(尺取法)

    传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K ...

  5. 5805 NanoApe Loves Sequence(想法题)

    传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K ( ...

  6. hdu 5273 Dylans loves sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...

  7. HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)

    NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...

  8. HDU 5805 NanoApe Loves Sequence (模拟)

    NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...

  9. hdu_5806_NanoApe Loves Sequence Ⅱ(双指针)

    题目链接:hdu_5806_NanoApe Loves Sequence Ⅱ 题意: 给你一段数,问你有多少个区间满足第K大的数不小于m 题解: 直接双指针加一下区间就行 #include<cs ...

随机推荐

  1. go语言编辑器:liteide

    LiteIDE is a simple, open source, cross-platform Go IDE. LiteIDE是一款开源.跨平台的轻量级Go语言集成开发环境(IDE). 项目地址:h ...

  2. javascript 对象初探 (四)--- 内建对象之旅之Array

     我们不要去纠结神马是内建对象,神马是內建构造器.到后来你们便会发现其实她们都是对象. Array()是一个构建数组的內建构造器函数: var arr = new Array(); 与下面的是等效的: ...

  3. Javascript - Arraylike的7种实现

    jQuery的崛起让ArrayLike(类数组)在javascript中大放异彩,它的出现为一组数据的行为(函数)扩展提供了基础. 类数组和数组相似,具有数组的某些行为,但是它相比数组可以更加自由的扩 ...

  4. The quieter you become,The more you are able to hear.

  5. DevExpress .NET界面开发示例大全

    说到做.net界面开发,很多人应该都会想到DevExpress. 它的 .net界面开发系列一共有7个版本:WinForms.ASP.NET.MVC.WPF.Silverlight.Windows 8 ...

  6. ubuntu制作本地源

    背景 平时apt-get install安装软件时,下载的deb文件都会存放在/var/cache/apt/archives/下,为了今后重装或给别人用,特别是没有网络时,这些deb文件实际上是可以派 ...

  7. Android.mk相关知识

    Android.mk是Android提供的一种makefile文件,用来指定诸如编译生成so库名.引用的头文件目录.需要编译的.c/.cpp文件和.a静态库文件等.要掌握jni,就必须熟练掌握Andr ...

  8. 【原】Github系列之一:一起做仿天气类应用中的实时模糊效果LiveBlur

    从本文开始,我将专门开辟一个Github Code系列,开源自己写的一部分有意思而且实用的demo,共同学习.以前都发布在git OSChina上,后面有空会陆陆续续整理到Github上.OSChin ...

  9. iOS 上传新版本到AppStore时报错ITMS-90034

    今天打包新版本上传到AppStore时报错 ERROR ITMS-90034:"Missing or invalid signature.The bundle'com.xxx.xxx' at ...

  10. 【问题排查】StringIndexOutOfBoundsException

    工作中遇到 java.lang.StringIndexOutOfBoundsException ,查看网上资料,总结如下 1.异常定义: Java API指出StringIndexOutOfBound ...