传送门

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. 深入理解SQL注入绕过WAF和过滤机制

    知己知彼,百战不殆 --孙子兵法 [目录] 0x0 前言 0x1 WAF的常见特征 0x2 绕过WAF的方法 0x3 SQLi Filter的实现及Evasion 0x4 延伸及测试向量示例 0x5 ...

  2. node.js+socket.io配置详解

    由于我是在win7的环境下,在这里就以win7系统为例进行讲解了. 首先需要在nodejs官网下载最新版的node.js,下载完毕直接安装即可,安装成功后在cmd命令行中执行node指令,如下结果就说 ...

  3. MapReduce 的架构

    主从结构 主节点,只有一个 : JobTracker   ,JobTracker 一般情况下,运行在 namenode 这台机器上. 从节点,有很多个 : TaskTrackers  ,  部署在剩下 ...

  4. ab

     ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed ...

  5. ORACLE lag()与lead() 函数

    一.简介 lag与lead函数是跟偏移量相关的两个分析函数,通过这两个函数可以在一次查询中取出同一字段的前N行的数据(lag)和后N行的数据(lead)作为独立的列,从而更方便地进行进行数据过滤.这种 ...

  6. 鸟哥私房菜学习(一)——Linux背景了解

    1.Linux,继承鱼Unix 2.Unix档案系统的两个重要概念 3.几个主要的 Linux distributions 发行者网址: • Red Hat: http://www.redhat.co ...

  7. WPF SpreadSheetGear电子表单

    我们经常会碰到生成Excel 界面并在其上操作的功能开发. 比如如下界面,我们需要在菜单里添加一个菜单按钮"Columns To Rows Transform" 功能是对多列批量转 ...

  8. 用grunt搭建web前端开发环境

    1.前言 本文章旨在讲解grunt入门,以及讲解grunt最常用的几个插件的使用. 2.安装node.js Grunt和所有grunt插件都是基于nodejs来运行的,如果你的电脑上没有nodejs, ...

  9. 第9章 Shell基础(4)_Bash的运算符及环境变量配置文件

    5. Bash的运算符 5.1 数值运算与运算符 5.1.1 declare 声明变量类型:#declare [+/-] [选项] 变量名 选项 说明 - 给变量设定类型属性 + 取消变量的类型属性 ...

  10. [No0000A6]Visual Studio 2015 中的常用命令的默认键盘快捷键-VS2015 Shortcut

    注意:你也可以通过打开"选项"对话框,展开"环境"节点,然后选择"键盘",查找任何命令的快捷键. Build(生成) 命令 键盘快捷键 [上 ...