【HDU】3530 Subsequence子序列
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Problem 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
翻译
子序列
时间限制:2000/1000 MS(Java /其他)
内存限制:65536/32768 K(Java /其他)
问题描述
有一个整数序列。您的任务是找到满足以下条件的最长子序列:子序列的最大元素和最小元素之间的差不小于m且不大于k。
输入
有多个测试用例。
对于每个测试用例,第一行都有三个整数n,m和k。n是序列的长度,并且在[1,100000]范围内。m和k在[0,1000000]范围内。第二行具有n个整数,均在[0,1000000]范围内。
继续到文件末尾。
输出
对于每个测试用例,在一行上打印子序列的长度。
样本输入
5 0 0
1 1 1 1 1
5 0 3

本文介绍了一种寻找特定条件下最长子序列的有效算法。通过维护两个单调队列来追踪序列中的最大值和最小值,该算法能在O(n)的时间复杂度内解决子序列问题。
最低0.47元/天 解锁文章
442

被折叠的 条评论
为什么被折叠?



