HDU 3530 Subsequence
来源:互联网 发布:2017网络效应判断题 编辑:程序博客网 时间:2024/06/05 12:46
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
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
单调队列。
用两个单调队列维护最大值和最小值。
#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<queue>#include<stack>using namespace std;#define ll long long#define getMax(a,b) a>b?a:b#define getMin(a,b) a<b?a:bconst int N=1e+5+5;int q[N],p[N],h1,h2,r1,r2;int a[N];int main(){ int n,m,k,i; while (~scanf("%d%d%d",&n,&m,&k)) { h1=h2=r1=r2=0; int ans=0,cur=1; for (i=1;i<=n;i++) { scanf("%d",&a[i]); while (h1<r1&&a[q[r1-1]]<a[i]) //递减 r1--; q[r1++]=i; while (h2<r2&&a[p[r2-1]]>a[i]) //递增 r2--; p[r2++]=i; while (h1<r1&&h2<r2&&a[q[h1]]-a[p[h2]]>k) //选择下标小的 { if (q[h1]<p[h2]) cur=q[h1++]+1; else cur=p[h2++]+1; } if (h1<r1&&h2<r2&&a[q[h1]]-a[p[h2]]>=m) if (ans<i-cur+1) ans=i-cur+1; } printf("%d\n",ans); } return 0;}
0 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 单调队列
- QLibrary 动态加载外部库文件
- java身份证识别
- Android基础类之BaseAdapter
- android 出现 cannot resolve symbol r
- swift实现微信通讯录列表TableView的创建
- HDU 3530 Subsequence
- Qt 跨UI线程的数据交换和信号-槽调用实现方案汇总
- 【iOS-报错】:“App Transport Security has blocked a cleartext HTTP”
- python 关于获取某一目录下的所有文件名并保存至txt文件
- ruby 中super和super()的区别
- Razor引擎学习:RenderBody,RenderPage和RenderSection
- 使用ListAcyivity实现动态菜单列表
- 【NOI OJ】1455 An Easy Problem(简单模拟题)
- 欢迎使用CSDN-markdown编辑器