HDU 1806
http://acm.hdu.edu.cn/showproblem.php?pid=1806
非常玄妙的rmq问题,这个st算法有点神
#include <iostream>
#include <cmath>
using namespace std ;
int dp[][] ;
int a[],b[] ;
void makermq(int n,int *tt)
{
for(int i= ;i<n ;i++)
dp[i][]=tt[i] ;
for(int j= ;(<<j)<=n ;j++)
for(int i= ;i+(<<j)-<n ;i++)
dp[i][j]=max(dp[i][j-],dp[i+(<<(j-))][j-]) ;
}
int rmq(int l,int r)
{
int k=(int)(log((r-l+)*1.0)/log()) ;
return max(dp[l][k],dp[r-(<<k)+][k]) ;
}
int bs(int l,int r)
{
int temp=a[r] ;
while(l<r)
{
int mid=(l+r)>> ;
if(a[mid]>temp)
r=mid- ;
else if(a[mid]<temp)
l=mid+ ;
else
r=mid ;
}
return r ;
}
int main()
{
int n,q ;
while(~scanf("%d",&n),n)
{
scanf("%d",&q) ;
for(int i= ;i<n ;i++)
scanf("%d",&a[i]) ;
int cnt ;
for(int i=n- ;i>= ;i--)
{
if(i==n-)
cnt= ;
else
{
if(a[i]==a[i+])
cnt++ ;
else
cnt= ;
}
b[i]=cnt ;
}
makermq(n,b) ;
while(q--)
{
int l,r ;
scanf("%d%d",&l,&r) ;
l-- ;r-- ;
int temp=bs(l,r) ;
int ans=r-temp+ ;
r=temp- ;
if(l>r)
printf("%d\n",ans) ;
else
printf("%d\n",max(ans,rmq(l,r))) ;
}
}
return ;
}
HDU 1806的更多相关文章
- hdu 1806 rmq
找到一个区间内出现最多的数的次数 10 3 //10个数字三次询问 -1 -1 1 1 1 1 3 10 10 10 2 3 1 10 5 10 0 143 #include<cstdio> ...
- [HDU 1806] Frequent values
Frequent values Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 1806 Frequent values 线段树
题目链接 给一个非递减数列, n个数, m个询问, 每个询问给出区间[L, R], 求这个区间里面出现次数最多的数的次数. 非递减数列, 这是最关键的一个条件... 需要保存一个区间最左边的数, 最右 ...
- hdu 1806(线段树区间合并)
Frequent values Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- poj 1806 Frequent values(RMQ 统计次数) 详细讲解
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1806 题目大意:给你一个非降序排列的整数数组,你的任务是对于一系列的询问,(i,j),回答序列中出现次 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- Permission denied: mod_fcgid
[Tue Jun 16 13:29:08 2015] [warn] (13)Permission denied: mod_fcgid: spawn process /var/www/cgi-bin/g ...
- LeetCode——Longest Word in Dictionary through Deleting
1. Question Given a string and a string dictionary, find the longest string in the dictionary that c ...
- Putting Apache Kafka To Use: A Practical Guide to Building a Stream Data Platform-part 1
转自: http://www.confluent.io/blog/stream-data-platform-1/ These days you hear a lot about "strea ...
- nwafu - java实习 JDBC练习 - 学生信息系统界面
学生信息系统界面的实现 - JDBC writer:pprp 登录界面的实现: 分为两个部分: 1.LoginFrame.java : 用windowbuilder进行快速搭建界面,构建好登录的界面, ...
- Docker 学习记录
docker logs 查看日志 docker logs 容器id docker logs -f 容器id 这次命令后面添加了一个新的标识 -f. 和 tail -f 类似, docker logs ...
- ABP 源码分析汇总之 AutoMapper
AutoMapper 是一个对象映射工具, 安装时只需要安装 如下即可: 有关于它的介绍,参考官网:http://automapper.org/ AutoMapper使用比较简单,还是直奔主题,看一下 ...
- ElasticSearch介绍与安装
什么是ES? 1基于Apache Lucene构建的开源搜索引擎 2采用java编写,提供简单易用的RESTFul API 3轻松的横向扩展,可支持PB级的结构化或非结构化数据处理 ES的应用场景? ...
- Angular单元测试系列
Angular单元测试系列 - 大纲Angular单元测试系列 - 简介Angular单元测试系列 - 如何使用Jasmine进行Angular单元测试Angular单元测试系列 - Router.C ...
- [spring]xml配置文件中的"classpath:"与"classpath*:"的区别
<bean id="sessionFactorySaas" class="org.mybatis.spring.SqlSessionFactoryBean" ...
- pwm计时器
1 PWM timer定时器与(watchdog差不多)2 5个16位的定时器,独立的,其中,NO PIN 没有输出.16表示ffff,和ADC中10表示3FF一样.而寄存器都是32位.(以后6410 ...