题目链接:

NanoApe Loves Sequence Ⅱ

Time Limit: 4000/2000 MS (Java/Others)   

 Memory Limit: 262144/131072 K (Java/Others)

Problem 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 Input
1
7 4 2
4 2 7 7 6 5 1
 
Sample Output
18
 
题意:
 
给一个序列,问区间第K大的数大于等于m的区间个数是多少?
 
思路:
 
处理出大于等于m的区间前缀和,然后尺取法搞;
 
AC代码:
 
/************************************************
┆ ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓   ┏━┛ ┆
┆  ┃   ┃  ┆      
┆  ┃   ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃    ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e5+10;
const int maxn=2e3+14;
const double eps=1e-12; int n,m,a[N],sum[N],k; int main()
{
int t;
read(t);
while(t--)
{
read(n);read(m);read(k);
For(i,1,n)
{
read(a[i]);
if(a[i]>=m)sum[i]=sum[i-1]+1;
else sum[i]=sum[i-1];
}
LL ans=0;
int r=1;
For(i,1,n-k+1)
{
r=max(i+k-1,r);
while(sum[r]-sum[i-1]<k&&r<=n)r++;
if(r<=n&&r-i+1>=k)ans=ans+(n-r+1);
}
cout<<ans<<"\n";
}
return 0;
}

  

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

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

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

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

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

  3. NanoApe Loves Sequence Ⅱ(尺取法)

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

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

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

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

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

  6. HDU 5806 NanoApe Loves Sequence Ⅱ

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

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

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

  8. 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 + ...

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

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

随机推荐

  1. srm 541

    资瓷点这里阅读该文章O_o 250 Solution 水题,最暴力的方法枚举就可以 Code #include <bits/stdc++.h> using namespace std; # ...

  2. sql查字符串包含某字段查询

    select * from dbo.V_AgreementMaterialQuery where '上海市' like '%'+SaleRange+'%' ‘上海市’>SaleRange(上海)

  3. Java函数的基本知识

    http://blog.csdn.net/cxwen78/article/details/7322891主要从Java函数的定义,函数的特点,函数的应用,函数的重载四个方面来讲解Java函数. 一.函 ...

  4. Oracle 使用TRUNCATE TABLE删除所有行

    若要删除表中的所有行,则 TRUNCATE TABLE 语句是一种快速.有效的方法.TRUNCATE TABLE 与不含 WHERE 子句的 DELETE 语句类似.但是,TRUNCATE TABLE ...

  5. java Map 实现类的对比

    java为数据结构中的映射定义了一个接口 java.util.Map ,他有四个实现类

  6. Windows下Tomcat+nginx配置证书实现登录页https访问

    最近公司出于安全考虑,需要将登录页做成https访问,其他页面仍采用http访问,环境是Linux平台,web服务器采用Tomcat + Nginx.之前没接触过nginx,这两天网上查资料,试了好多 ...

  7. android开发系列之数据存储

    在我们的android实际开发过程,必不可少的一种行为操作对象就是数据.有些数据,对于用户而言是一次性的,这就要求我们每次进到App的时候,都需要去刷新数据.有些数据,对于用户而言又是具有一定时效性的 ...

  8. wampserver 安装多个php版本号报错之关键问题

    近期喜欢上用wampserver来搭建php本地执行环境 主要是一键安装 特easy 之前一直用的是 appserv 也挺好用的 用了wamp后 才发现wamp更好用 duang duang 默认下载 ...

  9. eclipse--windowBuilder

    https://www.eclipse.org/windowbuilder/ https://www.eclipse.org/windowbuilder/download.php Documentat ...

  10. 跟我一起写 Makefile(一)[转]

    原文链接 http://bbs.chinaunix.net/thread-408225-1-1.html(出处: http://bbs.chinaunix.net/) 陈皓 概述—— 什么是makef ...