当前位置:网站首页>【提高课】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]);
}
边栏推荐
- [source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
- Go variables and constants
- Okcc why is cloud call center better than traditional call center?
- Delete the code you wrote? Sentenced to 10 months!
- MySQL advanced SQL statement 2
- First acquaintance with string+ simple usage (II)
- Document declaration and character encoding
- Recyclerview add header
- go 变量与常量
- How to solve the code error when storing array data into the database
猜你喜欢
Déchirure à la main - tri
【力扣刷题】15.三数之和(双指针);17.电话号码的字母组合(递归回溯)
《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮
[JS event -- event flow]
FAQ | FAQ for building applications for large screen devices
[personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
Fluent icon demo
[tips] use Matlab GUI to read files in dialog mode
go 包的使用
Introduction to vmware workstation and vSphere
随机推荐
藍湖的安裝及使用
Thinkphp6 limit interface access frequency
[JS -- map string]
Delete the code you wrote? Sentenced to 10 months!
Recyclerview add header
[JS event -- event flow]
How to solve the code error when storing array data into the database
Which is better, industrial intelligent gateway or edge computing gateway? How to choose the right one?
【leetcode】81. Search rotation sort array II
Which insurance company has a better product of anti-cancer insurance?
uni-app - 实现获取手机验证码倒计时 60 秒(手机号+验证码登录功能)
Li Kou interview question 02.08 Loop detection
[personnel density detection] matlab simulation of personnel density detection based on morphological processing and GRNN network
Go语言介绍
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
Introduction to JSON usage scenarios and precautions
WPViewPDF Delphi 和 .NET 的 PDF 查看组件
Lost a few hairs, and finally learned - graph traversal -dfs and BFS
Welcome the winter vacation multi school league game 2 partial solution (B, C, D, F, G, H)
What is 5g industrial wireless gateway? What functions can 5g industrial wireless gateway achieve?