xtu summer individual 5 D - Subsequence
Subsequence
This problem will be judged on HDU. Original ID: 3530
64-bit integer IO format: %I64d Java class name: Main
Input
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
Sample Input
5 0 0
1 1 1 1 1
5 0 3
1 2 3 4 5
Sample Output
5
4
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int qa[maxn],qb[maxn],h1,h2,t1,t2;
int n,m,k,d[maxn],lst1,lst2;
int main(){
int i,ans;
while(~scanf("%d %d %d",&n,&m,&k)){
for(i = ; i <= n; i++)
scanf("%d",d+i);
lst2 = lst1 = h1 = h2 = ;
t1 = t2 = -;
ans = ;
for(i = ; i <= n; i++){
while(t1 >= h1 && d[qa[t1]] <= d[i]) t1--;
qa[++t1] = i;
while(t2 >= h2 && d[qb[t2]] >= d[i]) t2--;
qb[++t2] = i;
while(d[qa[h1]] - d[qb[h2]] > k){
if(qa[h1] < qb[h2]){
lst1 = qa[h1++];
}else lst2 = qb[h2++];
}
if(d[qa[h1]] - d[qb[h2]] >= m)
ans = max(ans,i-max(lst1,lst2));
}
printf("%d\n",ans);
}
return ;
}
/*
5 0 0
1 1 1 1 1
5 0 3
1 2 3 4 5
*/
xtu summer individual 5 D - Subsequence的更多相关文章
- xtu summer individual 4 C - Dancing Lessons
Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- xtu summer individual 3 C.Infinite Maze
B. Infinite Maze time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- xtu summer individual 2 E - Double Profiles
Double Profiles Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- xtu summer individual 2 C - Hometask
Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...
- 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 H ...
- xtu summer individual 2 D - Colliders
Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...
- xtu summer individual 1 C - Design the city
C - Design the city Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu D ...
- xtu summer individual 1 E - Palindromic Numbers
E - Palindromic Numbers Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %l ...
- xtu summer individual 1 D - Round Numbers
D - Round Numbers Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u D ...
随机推荐
- HTML_CSS入门学习
1 HTML 简介 下面解释什么是HTML,以及HTML标签和HTML文档的含义. 1.1 什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Te ...
- 扩展KMP的应用
扩展KMP的应用: 给出模板串S和串T,长度分别为Slen和Tlen,要求在线性时间内,对于每个S[i](0<=i<Slen),求出S[i..Slen-1]与T的 最长公共前缀长度,记为e ...
- Service官方教程(2)*IntentService与Service示例、onStartCommand()3个返回值的含义。
1.Creating a Started Service A started service is one that another component starts by calling start ...
- webpack 报错:Module build failed: Unknown word (1:1)
解决方法:一是确保css配置里的"style-loader"必须在"css-loader"之前,二是将整个css配置注释掉,如下图:
- Elasticsearch--集群管理_再平衡&预热
目录 控制集群的再平衡 再平衡 集群的就绪 集群再平衡设置 控制再平衡何时开始 控制同时在节点移动的分片数量 控制单个节点上同时初始化的分片数量 控制单个节点上同时初始化的主分片数量 控制分配的分片类 ...
- Bmob使用心得
1.在 Project 的 build.gradle 文件中添加 Bmob的maven仓库地址,示例如下:(注意文字说明部分): allprojects { repositories { jcente ...
- iOS - 事件处理全过程(补充)
事件处理的完整过程 1> 先将事件对象由上往下传递(由父控件传递给子控件),找到最合适的控件来处理这个事件. 2> 调用最合适控件的touches….方法 3> 如果调用了[supe ...
- RegisterClientScriptBlock和RegisterStartupScript的区别
RegisterClientScriptBlock在 Page 对象的 元素的开始标记后立即发出客户端脚本,RegisterStartupScript则是在Page 对象的 元素的结束标记之前发出该脚 ...
- Mybatis 分页插件 PageHelper
话不多说,直接导入.部署流程. 1. 引入插件依赖包: maven工程中,pom.xml文件下,添加插件配置项: 2. 配置插件拦截器: webapp -> WEB-INF 下添加 .xml配置 ...
- 虚拟机centOs Linux与Windows之间的文件传输
一.配置环境 虚拟机Linux:Fedora 9 文件传输工具:SSHSecureShellClient-3.2.9 二.实现步骤 1. 在Windows中安装文件传输工具SSHSecureShell ...