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的更多相关文章

  1. 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> ...

  2. [HDU 1806] Frequent values

    Frequent values Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. hdu 1806 Frequent values 线段树

    题目链接 给一个非递减数列, n个数, m个询问, 每个询问给出区间[L, R], 求这个区间里面出现次数最多的数的次数. 非递减数列, 这是最关键的一个条件... 需要保存一个区间最左边的数, 最右 ...

  4. hdu 1806(线段树区间合并)

    Frequent values Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  6. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  7. poj 1806 Frequent values(RMQ 统计次数) 详细讲解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1806 题目大意:给你一个非降序排列的整数数组,你的任务是对于一系列的询问,(i,j),回答序列中出现次 ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. zabbix_server.log大量提示cannot send list of active checks to "IP": host [HostName] not found

    zabbix server 日志大量提示上图信息 原因是 zabbix_agent.conf配置文件中配置的HostName与zabbix的web界面配置的不同导致的 zabbix_agent.con ...

  2. linux网络连接的查看和端口的监听

    网络软件都是由客户端和服务端组成,由服务端在服务器上监听指定的端口处理接收到的数据,而客户端是向服务器端监听的端口发送数据,并由服务器端对该数据进行处理,然后将处理结果返回给客户端. 那么我们在lin ...

  3. <The old man and the sea>

    Every day is a new day. It is better to be lucky. But i would rather be exact. Then when luck comes ...

  4. Thinkphp5 模块的自动生成

    首先到根目录下的build.php文件中去 是这样子滴: 然后去public目录中的index.php中去添加代码 这样子: 然后运行项目 就搞定了. 是不是美滋滋! 在public 下index.p ...

  5. JavaScript高级程序设计-读书笔记(7)

    第22章 高级技巧 1.高级函数 (1)安全的类型检测 在任何值上调用Object原生的toString()方法,都会返回一个[object NativeConstructorName]格式的字符串. ...

  6. ubuntu mac terminal install software

    http-server // ubuntu sudo npm install http-server -g npm node.js yarn

  7. Spring Boot的自动配置的原理

    Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器. 1.1.1.   ...

  8. IDEA 中使用 Vue 提示 namespace is not bound

    今天在 IDEA 中使用 vue.js 时提示我如下错误信息 解决方法: 把这个校验项目去掉就可以了.

  9. [spring]xml配置文件中bean属性的两种写法(p:configLocation <=> <property name="configLocation"/>)

    1.当作bean节点的属性:p:configLocation: <!-- mybatis文件配置,扫描所有mapper文件 --> <bean id="sqlSession ...

  10. ubuntu下python安装pandas和numpy等依赖库版本不兼容的问题RuntimeWarning: numpy.dtype size changed

    习惯了linux下用pip install numpy及pip install pandas命令了.折腾了好久了. 上来先在python3中pip3 install numpy装了numpy,然后再p ...