当前位置:网站首页>[improvement class] st table to solve the interval maximum value problem [2]
[improvement class] st table to solve the interval maximum value problem [2]
2022-07-02 04:16:00 【ZhgDgE】
【 Improvement course 】ST Table solves the interval maximum problem
This was written before , Now rearrange the template , The subscript of the minimum value can be returned .
ST Table calculation of interval minimum value :
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]);
}
边栏推荐
- 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语言
- Play with concurrency: what's the use of interruptedexception?
- Yolov5 network modification tutorial (modify the backbone to efficientnet, mobilenet3, regnet, etc.)
- 5g era is coming in an all-round way, talking about the past and present life of mobile communication
- IDEA xml中sql没提示,且方言设置没用。
- Go variables and constants
- go 变量与常量
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- A summary of common interview questions in 2022, including 25 technology stacks, has helped me successfully get an offer from Tencent
猜你喜欢
66.qt quick QML Custom Calendar component (supports vertical and horizontal screens)
PIP installation of third-party libraries
Nacos 配置中心整体设计原理分析(持久化,集群,信息同步)
Actual combat | use composite material 3 in application
《西线无战事》我们才刚开始热爱生活,却不得不对一切开炮
Typescript practice for SAP ui5
Three years of experience in Android development interview (I regret that I didn't get n+1, Android bottom development tutorial
A thorough understanding of the development of scorecards - the determination of Y (Vintage analysis, rolling rate analysis, etc.)
文档声明与字符编码
Playing with concurrency: what are the ways of communication between threads?
随机推荐
[JS event -- event flow]
Pytorch-Yolov5从0运行Bug解决:
The first practical project of software tester: web side (video tutorial + document + use case library)
Hands on deep learning (II) -- multi layer perceptron
Typescript practice for SAP ui5
MySQL advanced SQL statement 2
Pytorch---使用Pytorch进行鸟类的预测
How to solve the code error when storing array data into the database
Use a mask to restrict the input of the qlineedit control
手撕——排序
[C language] basic learning notes
Which insurance company has a better product of anti-cancer insurance?
Play with concurrency: what's the use of interruptedexception?
Pandora IOT development board learning (RT thread) - Experiment 1 LED flashing experiment (learning notes)
Delete the code you wrote? Sentenced to 10 months!
Realizing deep learning framework from zero -- Introduction to neural network
【leetcode】34. Find the first and last positions of elements in a sorted array
Yyds dry inventory compiler and compiler tools
Bitmap principle code record
Installation et utilisation du lac bleu