题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=3530

Subsequence

Description

There is a sequence of integers. Your task is to find the longest subsequence that satisfies the following condition: the difference between the maximum element and the minimum element of the subsequence is no smaller than m and no larger than k.

Input

There are multiple test cases.
For each test case, the first line has three integers, n, m and k. n is the length of the sequence and is in the range $[1, 100000]$. m and k are in the range $[0, 1000000]$. The second line has n integers, which are all in the range $[0, 1000000]$.
Proceed to the end of file.

Output

For each test case, print the length of the subsequence on a single line.

Sample Input

5 0 0
1 1 1 1 1
5 0 3
1 2 3 4 5

Sample Output

5
4

RMQ线段树。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::set;
using std::map;
using std::min;
using std::max;
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::pair;
using std::vector;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define mid ((l+r)>>1)
#define lc (root<<1)
#define rc (root<<1|1)
const int Max_N = ;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ull;
int n, m, k, tmin, tmax;
struct SegTree {
struct Node { int max, min; }seg[Max_N << ];
inline void built(int root, int l, int r) {
if (l == r) {
scanf("%d", &seg[root].max), seg[root].min = seg[root].max;
return;
}
built(lc, l, mid);
built(rc, mid + , r);
seg[root].max = max(seg[lc].max, seg[rc].max);
seg[root].min = min(seg[lc].min, seg[rc].min);
}
inline void query(int root, int l, int r, int x, int y) {
if (x > r || y < l) return;
if (x <= l && y >= r) {
tmin = min(tmin, seg[root].min);
tmax = max(tmax, seg[root].max);
return;
}
query(lc, l, mid, x, y);
query(rc, mid + , r, x, y);
}
inline int query(int l, int r) {
tmin = INF, tmax = -INF;
query(, , n, l, r);
return tmax - tmin;
}
}seg;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int l, r, ans;
while (~scanf("%d %d %d", &n, &m, &k)) {
l = , ans = ;
seg.built(, , n);
rep(i, n) {
r = i;
if (l > r) continue;
while (seg.query(l, r) > k) l++;
if (seg.query(l, r) >= m && seg.query(l, r) <= k) ans = max(ans, r - l + );
}
printf("%d\n", ans);
}
return ;
}

hdu 3530 Subsequence的更多相关文章

  1. 【单调队列+尺取】HDU 3530 Subsequence

    acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对 ...

  2. HDU 3530 Subsequence(单调队列)

    传送门 Description There is a sequence of integers. Your task is to find the longest subsequence that s ...

  3. HDU - 3530 Subsequence (单调队列)

    Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. hdu 3530 Subsequence 单调队列

    题目链接 题目给出n个数, 一个下界m, 一个上界k, 让你求出最长的一段序列, 满足这段序列中的最大的数-最小的数<=k&&>=m, 输出这段长度. 可以维护两个队列, ...

  5. hdu 3530 "Subsequence" (单调队列)

    传送门 题意: 给出一个序列,求最长的连续子序列,使得 m ≤ Max-Min ≤ k 我的理解: 定义数组 a[] 存储输入的 n 个数: 定义两个双端队列: deque<int >qM ...

  6. Subsequence HDU - 3530

    Subsequence HDU - 3530 方法:单调队列区间最大最小 错误记录(本地写错)的原因:写成每次试着扩展右端点,却难以正确地处理"在多扩展右端点之后减去多扩展的部分" ...

  7. hdu 3530 单调队列最值

    /** HDU 3530 单调队列的应用 题意: 给定一段序列,求出最长的一段子序列使得该子序列中最大最小只差x满足m<=x<=k. 解题思路: 建立两个单调队列分别递增和递减维护(头尾删 ...

  8. Subsequence(hdu 3530)

    题意:给你一个长度为n的数列,要求一个子区间,使得区间的最大值与最小值的差s满足,m<=s<=k,求满足条件的最长子区间 /* 单调队列 我们可以用单调队列分别维护最大值和最小值 当差值大 ...

  9. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...

随机推荐

  1. extern “C”原理,用法以及使用场景-2016.01.05

    1 问题提出 在编程过程中,经常发现如下用法: #ifndef _FILE_NAME_H_ #define _FILE_NAME_H_ #ifdef __cplusplus extern " ...

  2. 【MariaDB】MariaDB编译参数

    参考: http://wangfeng7399.blog.51cto.com/3518031/1393146?utm_source=tuicool http://www.phperz.com/arti ...

  3. jquery ajax 保存讲解

    jquery ajax 参数传递与数据保存实例是一款适合于初学者用的,首先我们是讲一下关于如何利用ajax +php进行数据操作,然后再详细的介绍关于jquery ajax的帮助说明. jquery ...

  4. servlet 启动加载配置文件及初始化

    在servlet开发中,会涉及到一些xml数据的读取和一些初始化方法的调用.可以在tomcat启动的时候,加载一个servlet去初始化一些数据. 摘自 http://stone02111.iteye ...

  5. boost:thread使用实例

    /************************************************************************/ /*功能描述: boost thread使用实例 ...

  6. webstorm & phpstorm破解

    webstorm: http://idea.qinxi1992.cn/ http://idea.goxz.gq http://v2mc.net:1017 http://idea.imsxm.com h ...

  7. JavaScript编程规范

    最近看NodeJS中,有一部分写JS约定俗成的编程规范(附录B,详情参考附件),感觉在实际工作中能用到, 大致意思分享给大家,详情参考附件: 1.缩进:建议两空格 作为Node.js代码的缩进标记: ...

  8. HTML5上传图片预览

    <!DOCTYPE html> <html> <head> <title>HTML5上传图片预览</title> <meta http ...

  9. 使用BootStrap制作用户登录UI

    先看看劳动成果 布局 左右各一半(col-md-6) 左侧登录框占左侧一半的10/12 右侧是登录系统的注意事项 使用到的BootStrap元素 well 输入框组(input-group) 按钮(b ...

  10. ASP.NET MVC5 第4章

    参考资料<ASP.NET MVC5 高级编程>第5版 第4章 模型 本章所探讨的模型是要显示.保存.创建.更新和删除的对象. 基架指使用 MVC 提供的工具为每个模型对象的标准索引构建.创 ...