当前位置:网站首页>【提高课】ST表解决区间最值问题【2】
【提高课】ST表解决区间最值问题【2】
2022-07-02 04:10:00 【ZhgDgE】
【提高课】ST表解决区间最值问题
这是之前写的,现在重新整理了模板,可以返回最小值的下标。
ST 表求区间最小值:
struct st_pair{
int w, idx;
bool operator < (const st_pair & x) const{
return w < x.w;
}
};
st_pair f[N][LG];
void init(){
rep(j, 0, LG - 1){
for(int i = 1; i + (1 << j) - 1 <= n; i ++ ){
if(!j) f[i][j] = {
a[i], i};
else f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
}
}
}
st_pair query(int l, int r){
int k = __lg(r - l + 1);
return min(f[l][k], f[r - (1 << k) + 1][k]);
}
边栏推荐
- Influence of air resistance on the trajectory of table tennis
- Pytorch---使用Pytorch进行图像定位
- Pytorch---使用Pytorch进行鸟类的预测
- 集成底座方案演示说明
- Recently, the weather has been extremely hot, so collect the weather data of Beijing, Shanghai, Guangzhou and Shenzhen last year, and make a visual map
- First acquaintance with string+ simple usage (II)
- Pytorch---使用Pytorch实现U-Net进行语义分割
- 【leetcode】34. Find the first and last positions of elements in a sorted array
- 如何解决在editor模式下 无法删除物体的问题
- Actual combat | use composite material 3 in application
猜你喜欢
云服务器的安全设置常识
How much can a job hopping increase? Today, I saw the ceiling of job hopping.
初识P4语言
树莓派GPIO引脚控制红绿灯与轰鸣器
Nacos 配置中心整体设计原理分析(持久化,集群,信息同步)
整理了一份ECS夏日省钱秘籍,这次@老用户快来领走
MySQL error: expression 1 of select list is not in group by claim and contains nonaggre
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
【人员密度检测】基于形态学处理和GRNN网络的人员密度检测matlab仿真
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
随机推荐
【leetcode】34. Find the first and last positions of elements in a sorted array
Today's plan: February 15, 2022
Microsoft Research Institute's new book "Fundamentals of data science", 479 Pages pdf
PIP installation of third-party libraries
Is the product of cancer prevention medical insurance safe?
Basic operations of MySQL database (based on tables)
A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
go 包的使用
Jetpack's livedata extension mediatorlivedata
Qt插件之Qt Designer插件实现
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
How should the team choose the feature branch development mode or trunk development mode?
Which insurance company has a better product of anti-cancer insurance?
Wechat applet calculates the distance between the two places
Thinkphp6 limit interface access frequency
5G时代全面到来,浅谈移动通信的前世今生
Recently, the weather has been extremely hot, so collect the weather data of Beijing, Shanghai, Guangzhou and Shenzhen last year, and make a visual map
初识P4语言
Go variables and constants
LCM of Spreadtrum platform rotates 180 °