推荐博客 : https://blog.csdn.net/BerryKanry/article/details/70177006

ST表通常用于RMQ问题中,询问某个区间的最值这类问题中

ST表的核心部分就是 st[i][j] ,表示以 i 为起点跳跃 2^j 所经路径的最值。

更新的时候利用dp的思想

代码示例 :

void init(){
LOG[0] = -1;
for(int i = 1; i <= 100000; i++) LOG[i] = LOG[i/2]+1; for(int i = 1; i <= LOG[n]; i++){
for(int j = 1; j+(1<<i)-1 <= n; j++){
st[j][i] = max(st[j][i-1], st[j+(1<<(i-1))][i-1]);
}
}
}

至于查询是可以O(1)实现的

int ans = max(st[a][k], st[b-(1<<k)+1][k]);

还有关于求每个数的对数的LOG数组也是个重点,在上面

int st[maxn][20]; // 最大值为例
int n;
int LOG[maxn]; void init(){
LOG[0] = -1;
for(int i = 1; i <= 100000; i++) LOG[i] = LOG[i/2]+1; for(int i = 1; i <= LOG[n]; i++){
for(int j = 1; j+(1<<i)-1 <= n; j++){
st[j][i] = max(st[j][i-1], st[j+(1<<(i-1))][i-1]);
}
}
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout); cin >> n;
for(int i = 1; i <= n; i++){
scanf("%d", &st[i][0]);
}
init();
//for(int i = 1; i <= n; i++){
//for(int j = 0; j <= LOG[n]; j++){
//printf("%d ", st[i][j]);
//}
//printf("\n");
//}
int m, a, b; // m个查询
cin >> m;
for(int i = 1; i <= m; i++){
scanf("%d%d", &a, &b); int k = LOG[b-a+1]
int ans = max(st[a][k], st[b-(1<<k)+1][k]);
printf("%d\n", ans);
}
return 0;
}

初识 ST 表的更多相关文章

  1. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  2. 【BZOJ-2006】超级钢琴 ST表 + 堆 (一类经典问题)

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2473  Solved: 1211[Submit][Statu ...

  3. 【BZOJ-3956】Count ST表 + 单调栈

    3956: Count Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 173  Solved: 99[Submit][Status][Discuss] ...

  4. 【BZOJ-4569】萌萌哒 ST表 + 并查集

    4569: [Scoi2016]萌萌哒 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 459  Solved: 209[Submit][Status] ...

  5. 【BZOJ-4310】跳蚤 后缀数组 + ST表 + 二分

    4310: 跳蚤 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 180  Solved: 83[Submit][Status][Discuss] De ...

  6. HDU5726 GCD(二分 + ST表)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence of N(N≤100, ...

  7. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  8. Bzoj 2006: [NOI2010]超级钢琴 堆,ST表

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 2222  Solved: 1082[Submit][Statu ...

  9. ST表poj3264

      /* ST表多次查询区间最小值 设 g[j][i] 表示从第 i 个数到第 i + 2 ^ j - 1 个数之间的最小值 类似DP的说 ans[i][j]=min (ans[i][mid],ans ...

随机推荐

  1. H3C 高级ACL

  2. python模块之random模块

    random模块 随机模块,用于处理随机问题. import random # 随机整数 print(random.randint(0, 9)) # 0到9之间随机一个整数 print(random. ...

  3. React---钩子函数

    钩子函数的状态有4个阶段: <p>1.初始化阶段  (componentWillMount() || componentDidMount()) </p>             ...

  4. linux scull 中的设备注册

    在内部, scull 使用一个 struct scull_dev 类型的结构表示每个设备. 这个结构定义为: struct scull_dev { struct scull_qset *data;  ...

  5. ActiveMQ安装报错Wrapped Stopped解决办法

    在安装ActiveMQ的时候遇到了这个问题,一直报Wrapper Stopped 先开始也是修改环境变量,重启电脑,发现没有用,后来打开任务管理器,关闭了erl.exe,就成功了. 原文地址:http ...

  6. Node.js Windows Binary二进制文件安装

    1.下载文件 安装包的下载路径为:https://nodejs.org/en/download/ 选择你需要的版本,这里我选择了 Windows Binary 64-bit 版本. 2.配置npm安装 ...

  7. codeforces 86D,Powerful array 莫队

    传送门:https://codeforces.com/contest/86/problem/D 题意: 给你n个数,m次询问,每次询问问你在区间l,r内每个数字出现的次数的平方于当前这个数的乘积的和 ...

  8. 数据预处理以及探索性分析(EDA)

    1.根据某个列进行groupby,判断是否存在重复列. # Count the unique variables (if we got different weight values, # for e ...

  9. JMeter Web测试计划

    在本节中,将学习如何创建测试网页的基本测试计划. 出于演示测试目的,我们将测试URL - https://www.yiibai.com/ 的网页性能. 创建JMeter测试计划 进入到JMeter安装 ...

  10. VRchat模型之unity

    VRChat模型制作及上传总篇(包含总流程和所需插件):https://www.cnblogs.com/raitorei/p/12015876.html 0.新建工程, 导入VRCSDK及动态骨骼插件 ...