传送门

NanoApe Loves Sequence Ⅱ

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 1585    Accepted Submission(s): 688

Description

NanoApe, the Retired Dog, has returned back to prepare for for the National Higher Education Entrance Examination!

In math class, NanoApe picked up sequences once again. He wrote down a sequence with n numbers and a number m on the paper.

Now he wants to know the number of continous subsequences of the sequence in such a manner that the k-th largest number in the subsequence is no less than m.

Note : The length of the subsequence must be no less than k.

Input

The first line of the input contains an integer T, denoting the number of test cases.

In each test case, the first line of the input contains three integers n,m,k.

The second line of the input contains n integers A1,A2,...,An, denoting the elements of the sequence.

1≤T≤10, 2≤n≤200000, 1≤k≤n/2, 1≤m,Ai≤109

Output

For each test case, print a line with one integer, denoting the answer.

Sample Output

17 4 24 2 7 7 6 5 1

Sample Output

18

思路

题意:

退役狗 NanoApe 滚回去学文化课啦!
在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n 的数列,他又根据心情写下了一个数 m。
他想知道这个数列中有多少个区间里的第 k 大的数不小于 m,当然首先这个区间必须至少要有 k 个数啦。

 题解:求数列中多少个区间第k大不小于m,那么我们可以把数列中大于等于m的位置置1,其余置0,那么利用尺取法从头开始扫,找到每个位置开始和为k的区间的末位置,那么就知道总共有多少个区间了

 
#include<bits/stdc++.h>
using namespace std;
typedef __int64 LL;
const int maxn = 200005;
int num[maxn];

int main()
{
    //freopen("input.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while (T--)
    {
        int n,m,k,tmp;
        scanf("%d%d%d",&n,&m,&k);
        for (int i = 0;i < n;i++)
        {
            scanf("%d",&tmp);
            num[i] = tmp >= m?1:0;
        }
        int s = 0,t = 0;
        LL res = 0,sum = 0;
        for (;;)
        {
            while (t < n && sum < k)
            {
                sum += num[t++];
            }
            if (sum < k)    break;
            res += n - t + 1;
            sum -= num[s++];
        }
        printf("%I64d\n",res);
    }
    return 0;
}

  

5806 NanoApe Loves Sequence Ⅱ(尺取法)的更多相关文章

  1. NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 ...

  2. hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/13107 ...

  3. HDU5806:NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接:HDU5806 题意:找出有多少个区间中第k大数不小于m. 分析:用尺取法可以搞定,CF以前有一道类似的题目. #include<cstdio> using namespace ...

  4. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

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

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

  6. HDU 5806 NanoApe Loves Sequence Ⅱ ——(尺取法)

    题意:给出一个序列,问能找出多少个连续的子序列,使得这个子序列中第k大的数字不小于m. 分析:这个子序列中只要大于等于m的个数大于等于k个即可.那么,我们可以用尺取法写,代码不难写,但是有些小细节需要 ...

  7. HDU 5806 NanoApe Loves Sequence Ⅱ

    将大于等于m的数改为1,其余的改为0.问题转变成了有多少个区间的区间和>=k.可以枚举起点,二分第一个终点 或者尺取法. #pragma comment(linker, "/STACK ...

  8. HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

    http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...

  9. HDU 5806 - NanoApe Loves Sequence Ⅱ (BestCoder Round #86)

    若 [i, j] 满足, 则 [i, j+1], [i, j+2]...[i,n]均满足 故设当前区间里个数为size, 对于每个 i ,找到刚满足 size == k 的 [i, j], ans + ...

随机推荐

  1. 全球首个实战类微信小程序开发教程

    小木学堂专注于企业实战开发和经验传授,所以微信小程序诞生这么大的事怎么能不带着大家一起学习学习呢,所以小木学堂讲师连夜赶工学习并实战开发了微信小应用的第一个程序,并录制了课程现免费分享给大家.这个速度 ...

  2. JavaScript标准参考教材(alpha)--笔记

    一.导论 二.基本语法 1.严格来说var a=1与a=1效果不太一样,delete命令无法删除前者. JavaScirpt是一种动态类型语言,也就是说,变量的类型没有限制,可以赋予各种类型的值. J ...

  3. Visual Studio 生成事件命令

    Visual Studio在生成项目工程前后,有时我们需要做一些特殊的操作,比如:拷贝生成的dll到指定目标下面等. 结合VS可以添加预先生成事件和后期生成事件,采用命令或bat批处理. 1.Visu ...

  4. [Modern OpenGL系列(一)]十步搞定OpenGL开发环境

    本文已同步发表在CSDN:http://blog.csdn.net/wenxin2011/article/details/51292143 OpenGL官网:https://www.opengl.or ...

  5. APUE学习之多线程编程(三):线程属性、同步属性

    一.线程属性      可以使用pthread_attr_t结构修改线程默认属性,并这些属性和创建的线程练习起来,可以使用pthread_att_init函数初始化pthread_attr_t结构,调 ...

  6. linux下解压.tar.gz .tar.bz2

     从网络上下载到的源码包, 最常见的是 .tar.gz 包, 还有一部分是 .tar.bz2包要解压很简单 :.tar.gz     格式解压命令为          tar   -zxvpf   x ...

  7. 无法安装Windows Live“OnCatalogResult:0x80190194”错误的解决方法

    今天想安装一个博客客户端,结果安装一直报错"OnCatalogResult:0x80190194",百度查到了解决发放再此记录下来,以备后用. 到官网下载了一个在线安装程序,可是一 ...

  8. 3-linux下部署tomcat应用

    linux下部署tomcat应用 相关软件下载 jdk      http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downlo ...

  9. linux文件系统体系结构 和 虚拟文件系统(VFS)

    图 1. Linux 文件系统组件的体系结构 用户空间包含一些应用程序(例如,文件系统的使用者)和 GNU C 库(glibc),它们为文件系统调用(打开.读取.写和关闭)提供用户接口.系统调用接口的 ...

  10. gridview安卓实现单行多列横向滚动

    <GridLayout android:layout_width="match_parent" android:layout_height="match_paren ...