博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5289 Assignment rmq
阅读量:6801 次
发布时间:2019-06-26

本文共 1287 字,大约阅读时间需要 4 分钟。

Assignment

题目连接:

Description

Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to some staffs who were in the same group. In a group, the difference of the ability of any two staff is less than k, and their numbers are continuous. Tom want to know the number of groups like this.

Input

In the first line a number T indicates the number of test cases. Then for each case the first line contain 2 numbers n, k (1<=n<=100000, 0<k<=10^9),indicate the company has n persons, k means the maximum difference between abilities of staff in a group is less than k. The second line contains n integers:a[1],a[2],…,a,indicate the i-th staff’s ability.

Output

For each test,output the number of groups.

Sample Input

2

4 2
3 1 2 4
10 5
0 3 4 5 2 1 6 7 8 9

Sample Output

5

28

Hint

题意

给你n个数,然后连续的,且这个区间内最大值减去最小值的差小于k的话,就可以算作一队。

问你一共有多少种分队的方法。

题解:

暴力枚举左端点位置,然后二分枚举右端点,用一个rmq维护一下就好了。

代码

#include
using namespace std;const int maxn = 1e5+7;struct RMQ{ const static int RMQ_size = maxn; int n; int ArrayMax[RMQ_size][21]; int ArrayMin[RMQ_size][21]; void build_rmq(){ for(int j = 1 ; (1<
<= n ; ++ j) for(int i = 0 ; i + (1<

转载地址:http://gsuwl.baihongyu.com/

你可能感兴趣的文章
python的eval、exec函数使用总结
查看>>
js解析与序列化json数据(一)
查看>>
Oracle升级前备份和失败回退
查看>>
学习笔记之PostgreSQL / pgAdmin / Psycopg / PostGIS
查看>>
java设计模式-工厂方法模式
查看>>
SAP RFC通信模式
查看>>
基于jQuery+JSON的省市联动效果
查看>>
NABCD构建APP
查看>>
React 获取 url 参数 —— this.props.match
查看>>
乙佳荣第二次作业
查看>>
request请求的常用属性
查看>>
13-JS中的面向对象
查看>>
[转载]LeetCode: Gray Code
查看>>
优达学城数据分析师纳米学位——知识点总结2
查看>>
.Net 调用中国气象台Web Service
查看>>
BNU 51002 BQG's Complexity Analysis
查看>>
leetcode 7. Reverse Integer
查看>>
VC++6.0 自定义按钮,无标题对话框的拖动方法
查看>>
Ubuntu下 安装 window 虚拟机
查看>>
Urxvt最简配置
查看>>