xtu summer individual 5 D - Subsequence

Subsequence

Time Limit: 1000ms

Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 3530
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 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

解题:单调队列!马丹,真蛋疼,第一次搞这个。。。。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <vector>
 6 #include <climits>
 7 #include <algorithm>
 8 #include <cmath>
 9 #define LL long long
10 #define INF 0x3f3f3f3f
11 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 0
42 1 1 1 1 1
43 5 0 3
44 1 2 3 4 5
45 */

xtu summer individual 5 D - Subsequence,布布扣,bubuko.com

时间: 2024-08-03 15:29:08

xtu summer individual 5 D - Subsequence的相关文章

xtu summer individual 6 B - Number Busters

Number Busters Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 382B64-bit integer IO format: %I64d      Java class name: (Any) Arthur and Alexander are number busters. Today they've got a competition.

xtu summer individual 1 E - Palindromic Numbers

E - Palindromic Numbers Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this

xtu summer individual 6 D - Checkposts

Checkposts Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 427C64-bit integer IO format: %I64d      Java class name: (Any) Your city has n junctions. There are m one-way roads between the junctions. A

xtu summer individual 1 A - An interesting mobile game

An interesting mobile game Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 329564-bit integer IO format: %I64d      Java class name: Main XQ,one of the three Sailormoon girls,is usually playing mobile games o

xtu summer individual 2 C - Hometask

Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 154A64-bit integer IO format: %I64d      Java class name: (Any) Sergey attends lessons of the N-ish language. Each lesson he receives a hometas

xtu summer individual 5 F - Post Office

Post Office Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: 116064-bit integer IO format: %lld      Java class name: Main There is a straight highway with villages alongside the highway. The highway is repres

xtu summer individual 5 A - To Add or Not to Add

To Add or Not to Add Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 231C64-bit integer IO format: %I64d      Java class name: (Any) A piece of paper contains an array of n integers a1, a2, ..., an. Y

xtu summer individual 5 E - Burning Bridges

Burning Bridges Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 258864-bit integer IO format: %lld      Java class name: Main Ferry Kingdom is a nice little country located on N islands that are connected by

xtu summer individual 2 D - Colliders

Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 155D64-bit integer IO format: %I64d      Java class name: (Any) By 2312 there were n Large Hadron Colliders in the inhabited part of the unive