hdu 3530 Subsequence
题目连接
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的更多相关文章
- 【单调队列+尺取】HDU 3530 Subsequence
acm.hdu.edu.cn/showproblem.php?pid=3530 [题意] 给定一个长度为n的序列,问这个序列满足最大值和最小值的差在[m,k]的范围内的最长子区间是多长? [思路] 对 ...
- HDU 3530 Subsequence(单调队列)
传送门 Description There is a sequence of integers. Your task is to find the longest subsequence that s ...
- HDU - 3530 Subsequence (单调队列)
Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 3530 Subsequence 单调队列
题目链接 题目给出n个数, 一个下界m, 一个上界k, 让你求出最长的一段序列, 满足这段序列中的最大的数-最小的数<=k&&>=m, 输出这段长度. 可以维护两个队列, ...
- hdu 3530 "Subsequence" (单调队列)
传送门 题意: 给出一个序列,求最长的连续子序列,使得 m ≤ Max-Min ≤ k 我的理解: 定义数组 a[] 存储输入的 n 个数: 定义两个双端队列: deque<int >qM ...
- Subsequence HDU - 3530
Subsequence HDU - 3530 方法:单调队列区间最大最小 错误记录(本地写错)的原因:写成每次试着扩展右端点,却难以正确地处理"在多扩展右端点之后减去多扩展的部分" ...
- hdu 3530 单调队列最值
/** HDU 3530 单调队列的应用 题意: 给定一段序列,求出最长的一段子序列使得该子序列中最大最小只差x满足m<=x<=k. 解题思路: 建立两个单调队列分别递增和递减维护(头尾删 ...
- Subsequence(hdu 3530)
题意:给你一个长度为n的数列,要求一个子区间,使得区间的最大值与最小值的差s满足,m<=s<=k,求满足条件的最长子区间 /* 单调队列 我们可以用单调队列分别维护最大值和最小值 当差值大 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...
随机推荐
- Adobe AIR and Flex - 实现堆栈容器
1.需求描述: 在对云平台的监控中,我们经常需要在一张图上可视化的描述集群下的物理机所虚拟的虚拟机使用情况,以及超卖情况.那么传统的chart图就不满足我们的需求了,那么要实现这样一个定制化的char ...
- AD采样问题总结
说明:来源http://bbs.csdn.net/topics/390899032论坛讨论 一个100HZ的正弦波,我用300HZ的采样率去采样,那么根据香农定律是不是一秒钟就采集到300个点,因为这 ...
- js实现简单的滑动门和tab选项卡
思想:首先定义三个选项卡,可以用任何标签,只要如下图, 一共有三个ul,第一个ul给一个class,因为默认第一个选项卡的内容显示出来, 其他两个ul display:none: 当我鼠标移到第二个 ...
- plsql快捷开发
最近在开发过程中,遇到一些麻烦,就是开发效率问题,有时候其他同事使用PLSQL 编程效率明显高于自己,观察了好久,才发现他使用PLSQL 已经很长时间了而且,他自己也在其中添加了好多快捷方式, 1.登 ...
- c#实现每隔规定时间自动执行程序代码
c#实现每隔规定时间自动执行程序代码 在一般的项目中我们很少用到c#实现每隔规定时间自动执行程序代码,但是如果你经历的项目多,或者应用程序做的比较多的话,c#实现每隔规定时间自动执行程序代码就用的比 ...
- JSON对象遍历方法
JSON对象提前不知道其属性和结构,遍历其值 var json2 = { "name": "txt1", "name2": "tx ...
- java值得注意的几个问题
1.一个源文件中只能有一个类是public的,其他的都是默认权限的: 2.一个类只能作为public或者默认权限(就是没有修饰符的意思): 3.源文件的public类的名字必须要跟文件名保持一致,否则 ...
- echarts简单使用案例
先上效果图:
- jQuery在HTML文档加载完毕后自动执行某个事件;
原来onchange=“fucntionname(parms)”: <select name="country" id="selCountries_{$sn}&qu ...
- Java 中的抽象类及接口
抽象类使用 abstract 关键字修饰,该类即为抽象类. 抽象类的作用: 1.某些情况下,父类约束子类必须包含哪些方法,但不知道子类如何去实现这些方法. 2.可以从多个具有相同特征的类中抽象出一个抽 ...