题目连接

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. Could not resolve this reference. Could not locate the assembly

    Rebuild Project 的时候提示找不到NewtonJson 组件,重新添加了Dll(Newtonsoft.Json.dll),依然抛错. 解决办法,将Dll(Newtonsoft.Json. ...

  2. MYSQL--事务处理

    1.用begin,rollback,commit来实现 begin 开始一个事务 rollback 事务回滚 commit  事务确认 2.直接用set来改变mysql的自动提交模式 MYSQL默认是 ...

  3. linux进程状态

    系统维护的时候难免会遇到进程的状态的查询和管理,到底什么是R,有的是S,有的还是S+呢?一直有些混沌的问题,今天细细的来总结一下: ps是用来报告系统中程序执行状况的命令这个是无可厚非的,linux进 ...

  4. 如何查找Mac上的USB存储设备使用痕迹

    最近刚好有个案子的证物主机是MBP, OS X版本为El Capitan,案况与营业秘密外泄有关,当中要找有关USB存储设备的使用痕迹. 要提醒大家的是,不同版本的OS X,各种迹证的存放文件名称及路 ...

  5. CentOS6.5配置vim使支持Python

    CentOS6.5下开启vim对python的支持,配置方法如下: 1.检查系统已经安装了RPM包vim-enhanced; 2.复制默认的.vimrc初始化文件: # cp /usr/share/v ...

  6. 高仿精仿开心网应用android源码

    今天早上看到了一个不错的安卓应用源码项目,真的非常不错高仿精仿开心网应用android源码下载,希望大家能够喜欢.       原文:http://android.662p.com/thread-29 ...

  7. 搭建高性能计算环境(八)、应用软件的安装之gromacs

    1,下载安装新版本的gcc(高版本的gcc只是推荐使用的,系统自带的gcc4.4照样能正常编译.运行) wget http://ftp.tsukuba.wide.ad.jp/software/gcc/ ...

  8. jQuery bind and unbind (绑定和解除)

    测试:页面代码: <body> <input type="button" name="aaa" value="点击我"&g ...

  9. iOS初学者的AppStore上架应用"菜谱大师"开源了!

    本人是一名DoNet程序猿,在业余的时间自学了点iOS,于是就自己弄了一个小菜谱,自己要做菜的时候也就可以用自己的菜谱了. 现在将此应用开源给像我一样对iOS开发有兴趣,并且想学习iOS的园友,毕竟这 ...

  10. 获取屏幕分辨率(C#)

    C#获取屏幕分辨率的方法 static void Main(string[] args) { // 控制台程序,需要添加程序集: // using System.Drawing; // using S ...