hdu3530Subsequence rmq
//使用rmq办,ma[i][j],同i作为一个起点2^j阵列的最大长度值
//启动枚举问最长的子列
//枚举的最大长度2^(j-1)和2^(j)z之间
//然后在该范围内找到
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=100010;
int a[maxn],ma[maxn][25],mi[maxn][25];
int n,m,k;
void rmq()
{
for(int i=1;i<=n;i++)
ma[i][0]=mi[i][0]=a[i];
for(int j=1;j<=log((double)(n))/log(2.0);j++)
for(int i=1;i+(1<<j)-1<=n;i++)
{
ma[i][j]=max(ma[i][j-1],ma[i+(1<<(j-1))][j-1]);
mi[i][j]=min(mi[i][j-1],mi[i+(1<<(j-1))][j-1]);
}
}
int query(int a,int b)
{
int k=(int)(log((double)(b-a+1))/log(2.0));
return max(ma[a][k],ma[b-(1<<(k))+1][k])-min(mi[a][k],mi[b-(1<<(k))+1][k]);
}
int Maxlen(int st,int pos)
{
int j;
for(j=0;(pos+(1<<j))<=n;j++)
{
int tmp=query(st,pos+(1<<j));
if(tmp>k)
{
if(j==0)
return pos;
return Maxlen(st,pos+(1<<(j-1)));
}
}
if((pos+(1<<(j-1))==n))
return n;
else
return Maxlen(st,pos+(1<<(j-1)));
}
int main()
{
// freopen("in.txt","r",stdin);
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
rmq();
if(query(1,n)<m)
{
printf("0\n");
continue;
}
int ans=0;
for(int i=1;i<=n;i++)
{
int tmp=Maxlen(i,i-1);
ans=max(ans,tmp-i+1);
if(tmp==n||((n-i+1)<=ans))
break;
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
hdu3530Subsequence rmq的更多相关文章
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- UVA 11235Frequent values(RMQ)
训练指南P198 题意:给出一个非降序排列的整数数组a1, a2…… an,你的任务是对于一系列询问(i,j),回答ai, ai+1 ……aj 中出现的次数最多的次数 这题不仅学到了rmq的应用还学到 ...
- 51nod1174(RMQ)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1174 题意:中文题诶- 思路:RMQ模板题 关于RMQ: h ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1008 Function 二分+RMQ
Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...
- Gym 100646 F Tanks a Lot RMQ
Problem F: Tanks a Lot Imagine you have a car with a very large gas tank - large enough to hold what ...
- (RMQ版)LCA注意要点
inline int lca(int x,int y){ if(x>y) swap(x,y); ]][x]]<h[rmq[log[y-x+]][y-near[y-x+]+]])? rmq[ ...
- 洛谷P2412 查单词 [trie树 RMQ]
题目背景 滚粗了的HansBug在收拾旧英语书,然而他发现了什么奇妙的东西. 题目描述 udp2.T3如果遇到相同的字符串,输出后面的 蒟蒻HansBug在一本英语书里面找到了一个单词表,包含N个单词 ...
- POJ3368Frequent values[RMQ 游程编码]
Frequent values Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17581 Accepted: 6346 ...
- [tem]RMQ(st)
倍增思想 代码中有两个测试 #include <iostream> #include <cmath> using namespace std; const int N=1e5; ...
随机推荐
- Xah Lee Web 李杀网
Xah Lee Web 李杀网 ∑ Xah Lee Web 李杀网
- 黑马程序猿_ 利用oc的协议实现代理模式
先说下代理模式是什么吧 定义: 为其它对象提供一种代理以控制对这个对象的訪问.在某些情况下,一个对象不适合或者不能直接引用还有一个对象 而代理对象能够在client和目标对象之间起到中介的作用. 在看 ...
- 2014 CSDN博文大赛终于获奖名单发布
博文大赛第二阶段(2014年7月15日-2014年8月10日)已经结束,决赛获奖名单已在8月11日出炉. 现将获奖名单发布: 移动开发 NO.1 罗升阳 Luoshengyang S ...
- hbase基本概念和hbase shell经常使用命令使用方法
HBase是一个分布式的.面向列的开源数据库,源于google的一篇论文<bigtable:一个结构化数据的分布式存储系统>.HBase是Google Bigtable的开源实现,它利用H ...
- A Game of Thrones(10) - Jon
Jon climbed the steps slowly, trying not to think that this might be the last time ever. Ghost padde ...
- poj2253(最短路小变形)
题目连接:http://poj.org/problem?id=2253 题意:给出一个无向图,求一条1~2的路径使得路径上的最大边权最小. 分析:dij将距离更新改成取最大值即可,即dp[i]表示到达 ...
- Androidclient和server端数据交互的第一种方法
网上有非常多样例来演示Android客户端和server端数据怎样实现交互只是这些样例大多比較繁杂,对于刚開始学习的人来说这是不利的.如今介绍几种代码简单.逻辑清晰的交互样例,本篇博客介绍第一种: 一 ...
- 抢车位中的排名bug(比較使用了无符号数)
昨天把这个发在了qzone,想来还是怪怪的,还是转过来不吧,纯当发现了一个虫子,玩笑一下.只是csdn如今不能贴图,挺郁闷的,原文在http://user.qzone.qq.com/110907073 ...
- 王立平--Failed to push selection: Read-only file system
往android模拟器导入资源,失败. 提示:仅仅读文件. mnt是仅仅读文件.应点击sdcard.,在导入
- spring4.1+springmvc4.1+mybatis3.2.8+spring-security3.2.5集成环境建设
在最近使用的项目ssi+spring-security 结构体.建立你自己的家,这是什么环境. 只有记录的目的. 项目结构: 类文件: ...