HDU 3530 Subsequence
来源:互联网 发布:淘宝网雷丝高领打底衫 编辑:程序博客网 时间:2024/06/06 00:40
Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7550 Accepted Submission(s): 2555
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
Source
2010 ACM-ICPC Multi-University Training Contest(10)——Host by HEU
Recommend
zhengfeng | We have carefully selected several similar problems for you: 3535 3529 3528 3527 3415
//维护两个单调队列#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#define N 100010using namespace std;inline int max(int a ,int b) { return a>b?a:b; }int s1[N],s2[N],a[N];int main() { int n,m,k,top1,top2,last1,last2,tail1,tail2,Ans; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { for(int i=1; i<=n; i++) scanf("%d",&a[i]); memset(s1,0,sizeof(s1)); memset(s2,0,sizeof(s2)); top1 = 0,top2 = 0,tail1 = 0,tail2 = 0; Ans = 0,last1 = 0,last2 = 0; for(int i=1; i<=n; i++){ //max while(top1 < tail1 && a[s1[tail1 - 1]] <= a[i]) tail1--; //top1最大元素 s1[tail1++] = i; //min while(top2 < tail2 && a[s2[tail2 - 1]] >= a[i]) tail2--; //top2最小元素 s2[tail2++] = i; while(a[s1[top1]] - a[s2[top2]] > k){ if(s1[top1] < s2[top2]) last1 = s1[top1++]; else last2 = s2[top2++]; } if(a[s1[top1]] - a[s2[top2]] >= m) Ans = max(Ans,i - max(last1,last2)); } printf("%d\n",Ans); } return 0;}
- HDU 3530 Subsequence
- hdu 3530 Subsequence
- HDU 3530 Subsequence
- HDU - 3530 Subsequence
- HDU-3530-Subsequence
- hdu-3530-Subsequence
- HDU 3530 Subsequence
- hdu 3530 Subsequence
- HDU 3530 Subsequence
- HDU 3530 Subsequence
- hdu 3530 Subsequence
- HDU 3530 Subsequence
- [hdu 3530]Subsequence
- HDU 3530 Subsequence
- HDU 3530 Subsequence
- HDU 3530 Subsequence 【单调队列】
- hdu 3530 Subsequence //单调队列
- hdu 3530 Subsequence 单调队列
- Typeface
- 连续总结第二十八天
- 最小生成树k算法
- Centos下安装Ipython
- c++随笔
- HDU 3530 Subsequence
- Qt5+vs2015无法打开源文件moc_XXX.h/cpp的问题
- Struts2 概述
- 简析XML和HTML的区别
- 11.2
- java常见面试题之单例模式
- RocketMQ源码解析-PushConsumer(3)
- Android 组件学习笔记(九宫格游戏,imageview设置图片满屏技巧)
- string类方法