题目连接

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线段树。。

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. using std::set;
  10. using std::map;
  11. using std::min;
  12. using std::max;
  13. using std::cin;
  14. using std::cout;
  15. using std::endl;
  16. using std::find;
  17. using std::sort;
  18. using std::pair;
  19. using std::vector;
  20. #define sz(c) (int)(c).size()
  21. #define all(c) (c).begin(), (c).end()
  22. #define iter(c) decltype((c).begin())
  23. #define cls(arr,val) memset(arr,val,sizeof(arr))
  24. #define cpresent(c, e) (find(all(c), (e)) != (c).end())
  25. #define rep(i, n) for (int i = 1; i <= (int)(n); i++)
  26. #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
  27. #define pb(e) push_back(e)
  28. #define mp(a, b) make_pair(a, b)
  29. #define mid ((l+r)>>1)
  30. #define lc (root<<1)
  31. #define rc (root<<1|1)
  32. const int Max_N = ;
  33. const int INF = 0x3f3f3f3f;
  34. typedef unsigned long long ull;
  35. int n, m, k, tmin, tmax;
  36. struct SegTree {
  37. struct Node { int max, min; }seg[Max_N << ];
  38. inline void built(int root, int l, int r) {
  39. if (l == r) {
  40. scanf("%d", &seg[root].max), seg[root].min = seg[root].max;
  41. return;
  42. }
  43. built(lc, l, mid);
  44. built(rc, mid + , r);
  45. seg[root].max = max(seg[lc].max, seg[rc].max);
  46. seg[root].min = min(seg[lc].min, seg[rc].min);
  47. }
  48. inline void query(int root, int l, int r, int x, int y) {
  49. if (x > r || y < l) return;
  50. if (x <= l && y >= r) {
  51. tmin = min(tmin, seg[root].min);
  52. tmax = max(tmax, seg[root].max);
  53. return;
  54. }
  55. query(lc, l, mid, x, y);
  56. query(rc, mid + , r, x, y);
  57. }
  58. inline int query(int l, int r) {
  59. tmin = INF, tmax = -INF;
  60. query(, , n, l, r);
  61. return tmax - tmin;
  62. }
  63. }seg;
  64. int main() {
  65. #ifdef LOCAL
  66. freopen("in.txt", "r", stdin);
  67. freopen("out.txt", "w+", stdout);
  68. #endif
  69. int l, r, ans;
  70. while (~scanf("%d %d %d", &n, &m, &k)) {
  71. l = , ans = ;
  72. seg.built(, , n);
  73. rep(i, n) {
  74. r = i;
  75. if (l > r) continue;
  76. while (seg.query(l, r) > k) l++;
  77. if (seg.query(l, r) >= m && seg.query(l, r) <= k) ans = max(ans, r - l + );
  78. }
  79. printf("%d\n", ans);
  80. }
  81. return ;
  82. }

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. 【练习】trace文本重建控制文件

    这个小练习是针对控制文件全部丢失后怎么能快速的重建一个控制文件,快速的起库 1.备份控制文件到trace下 SQL> alter database backup controlfile to t ...

  2. 优秀的前端上传文件插件 web uploader

    WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览 ...

  3. 更改Pch配置

    在Build Settings 里搜索prefix  在第一个AppleLLVM.7.0 有一个 PrefixHeader 属性  在属性里添加 $(SRCROOT)/加上pch文件名字    然后编 ...

  4. div模仿select效果二:带搜索框

    项目需要,要做一个首字母快速定位的select,代码如下: HTML <div class="select_country" unselectable="on&qu ...

  5. 响应式Web设计基础

    本文所有内容来自Responsive Web Design Fundamentals 手机.大屏手机.平板电脑.桌面电脑.游戏控制台.电视.甚至是可穿戴设备,如此多的设备也形成了多种多样的屏幕尺寸.屏 ...

  6. 020ARM家族

    1.名称:6410.2440.210.A8.ARM9.ARM11.armv7.ARMv6(v:vsersion) 芯片的名称:6410.210.2440都是属于芯片的名称,都是来自三星公司: ARM核 ...

  7. 五、Eclipse编写struts.xml没有提示的问题

      五.Eclipse编写struts.xml没有提示的问题 原因:找不到约束文件 解决: 联网 手工配 a.eclipse的菜单:window\preferences

  8. openstack简介

    OpenStack是一个开源的云计算管理平台项目,由几个主要的组件组合起来完成具体工作.OpenStack支持几乎所有类型的云环境,项目目标是提供实施简单.可大规模扩展.丰富.标准统一的云计算管理平台 ...

  9. Aspose插件

    Eclipse安装地址: http://apps.aspose.com/marketplace/eclipse/asposewizardrepo

  10. 软件工程 speedsnail 第二次冲刺4

    20150521 完成任务:划线第四天,能蜗牛遇到线能反弹,加了障碍物: 遇到问题: 问题1 有一个方向碰到线没有反弹 解决1 没有解决 明日任务: 完善问题1