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 ...
随机推荐
- phonegap/cordova 升级版本
调用语句 : windows用户 npm update -g cordova 如果是 mac系统的用户 使用: 查看cordova信息 npm info cordova 查看cordova 版本 查 ...
- 要在一般处理程序中获取其他页面的session值
1.要在一般处理程序中获取其他页面的session值,需要引用名空间: using System.Web.SessionState; 2.然后继承一个接口:IRequiresSessionState, ...
- C# 反射操作方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- tcp timestamp
Description Protocol suite: TCP/IP. Protocol type: Transport layer protocol. Option length: 10 bytes ...
- 十六、Struts2文件上传与下载
文件上传与下载 1.文件上传前提:<form action="${pageContext.request.contextPath}/*" method="post& ...
- java Literals
Primitive Data Types The Java programming language is statically-typed, which means that all variabl ...
- ref和out的区别?
ref 和out的区别在面试中会常问到: 首先:两者都是按地址传递的,使用后都将改变原来参数的数值. 其次:ref可以把参数的数值传递进函数,但是out是要把参数清空,就是说你无法把一个数值从out传 ...
- shell 截取指定的字符串
按指定的字符串截取 1.第一种方法: ${varible##*string} 从左向右截取最后一个string后的字符串 ${varible#*string}从左向右截取第一个string后的字符串 ...
- C# 判断一字符串是否为合法数字(正则表达式)
判断一个字符串是否为合法整数(不限制长度) public static bool IsInteger(string s) { string pattern = @"^\d*$"; ...
- VS2008无法切换到视图设计器
编写人:CC阿爸 2014-2-17 近来用于干活的笔记本电脑实在太慢了,在领导的安排下,有幸更换了一台配置好的电脑.经过一天的努力,所有之前的开发软件都安装完成了.并且OS从xp升级到win7.SQ ...