当前位置:网站首页>-ST表模板
-ST表模板
2022-08-05 13:54:00 【Boletb】
ST表用于快速查询区间最大值
//用于寻找区间最大值
//ST模板
#include<bits/stdc++.h>
using namespace std;
#define N 100009
int a[N][30];
int n;
int b[N];
int max(int o,int p){
if(o>p){
return o;
}
return p;
}
void init(){
int i=0,j=0;
for(i=1;i<=n;i++){
a[i][0]=b[i];
}
for(i=1;(1<<i)<=n;i++){
for(j=1;j+(1<<i)<=n+1;j++){
a[j][i]=max(a[j][i-1],a[j+(1<<(i-1))][i-1]);
}
}
}
int search(int l,int r){
int k=log(r-l+1)/log(2);
int t=max(a[l][k],a[r-(1<<k)+1][k]);
return t;
}
int main()
{
int m;
scanf("%d %d",&n,&m);
int i=0;
for(i=1;i<=n;i++){
scanf("%d",&b[i]);
}
int x,y;
init();
for(i=1;i<=m;i++){
scanf("%d %d",&x,&y);
int end=search(x,y);//x,y表示的是每次查询的左右区间
printf("%d\n",end);
}
return 0;
}ST表的一道模板题
边栏推荐
- 深度学习之 11 卷积神经网络实现
- Memory mapping principle and mmap
- 当天期货开户次日就可以交易
- 十分钟教会你如何使用VitePress搭建及部署个人博客站点
- Under the heavy pressure of the epidemic, why is Watsons still profitable in the first half of the year?
- 中金财富炒股怎样线上开户?有没有安全上的问题??
- 爱可可AI前沿推介(8.5)
- 行云管家荣获第十一届中国财经峰会“2022杰出品牌形象奖”
- 一行简单的样式,让网页有「高级感」
- 《ABP Framework 极速开发》教程首发
猜你喜欢
随机推荐
国密是什么意思?属于商密还是普密?
使用 Redis 源码编译发布 Windows 版 Redis For Windows 发行包
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷可修饰材料表面
内存映射原理及mmap
Capacity upgrade helps computing power flow, the acceleration moment of China's digital economy
7.nodejs--egg框架简介、以及get、post请求
VINS-Mono result display
SQL中COUNT和SUM
服务端如何推送消息给客户端?
The memory problem is difficult to locate, that's because you don't use ASAN
@2023研考生:如何度过暑期研考备考“黄金期”
选择排名靠前的期货公司开户
Synchronized锁升级
并发刺客(False Sharing)——并发程序的隐藏杀手
王爽汇编语言第五章:【BX】和loop指令
Xingyun Butler won the "2022 Outstanding Brand Image Award" at the 11th China Finance Summit
"Original" "Tutorial" to add a small pendant of the telescopic sidebar to the Joe theme article page
C#员工考勤管理系统源码 考勤工资管理系统源码
IIoT系统架构
day7·拆包与装包









