博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
xtu summer individual 5 D - Subsequence
阅读量:4322 次
发布时间:2019-06-06

本文共 1966 字,大约阅读时间需要 6 分钟。

Subsequence

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on 
HDU. Original ID: 
64-bit integer IO format: %I64d      Java class name: Main
 
 
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 01 1 1 1 15 0 31 2 3 4 5

Sample Output

54

Source

 
解题:单调队列!马丹,真蛋疼,第一次搞这个。。。。。
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #define LL long long10 #define INF 0x3f3f3f3f11 using namespace std;12 const int maxn = 100100;13 int qa[maxn],qb[maxn],h1,h2,t1,t2;14 int n,m,k,d[maxn],lst1,lst2;15 int main(){16 int i,ans;17 while(~scanf("%d %d %d",&n,&m,&k)){18 for(i = 1; i <= n; i++)19 scanf("%d",d+i);20 lst2 = lst1 = h1 = h2 = 0;21 t1 = t2 = -1;22 ans = 0;23 for(i = 1; i <= n; i++){24 while(t1 >= h1 && d[qa[t1]] <= d[i]) t1--;25 qa[++t1] = i;26 while(t2 >= h2 && d[qb[t2]] >= d[i]) t2--;27 qb[++t2] = i;28 while(d[qa[h1]] - d[qb[h2]] > k){29 if(qa[h1] < qb[h2]){30 lst1 = qa[h1++];31 }else lst2 = qb[h2++];32 }33 if(d[qa[h1]] - d[qb[h2]] >= m)34 ans = max(ans,i-max(lst1,lst2));35 }36 printf("%d\n",ans);37 }38 return 0;39 }40 /*41 5 0 042 1 1 1 1 143 5 0 344 1 2 3 4 545 */
View Code

 

 

转载于:https://www.cnblogs.com/crackpotisback/p/3895911.html

你可能感兴趣的文章
错误提示总结
查看>>
实验二+070+胡阳洋
查看>>
Linux IPC实践(3) --具名FIFO
查看>>
Qt之模拟时钟
查看>>
第一次接触安卓--记于2015.8.21
查看>>
(转)在分层架构下寻找java web漏洞
查看>>
mac下多线程实现处理
查看>>
C++ ifstream ofstream
查看>>
跟初学者学习IbatisNet第四篇
查看>>
seL4环境配置
查看>>
Git报错:insufficient permission for adding an object to repository database .git/objects
查看>>
ajax跨域,携带cookie
查看>>
python 下载远程日志
查看>>
BZOJ 1600: [Usaco2008 Oct]建造栅栏( dp )
查看>>
nginx 高并发配置参数(转载)
查看>>
Jquery异步请求数据实例
查看>>
洛谷 CF937A Olympiad
查看>>
bzoj 3876: [Ahoi2014]支线剧情
查看>>
file_get_contens POST传值
查看>>
关于overflow:hidden
查看>>