当前位置:网站首页>ST表预处理时的数组证明
ST表预处理时的数组证明
2022-07-07 01:25:00 【Harris-H】
ST表预处理时的数组证明
a i = x ( 2 x ≤ i < 2 x + 1 ) a_i=x(2^x\le i< 2^{x+1}) ai=x(2x≤i<2x+1)
递推方程: a i = a i 2 + 1 a_i=a_{\small\dfrac{i}{2}}+1 ai=a2i+1
证明:
a i 2 = x a_{\dfrac{i}{2}}=x a2i=x
2 x ≤ i 2 < 2 x + 1 2^x\le \dfrac{i}{2}<2^{x+1} 2x≤2i<2x+1
∴ 2 x + 1 ≤ i < 2 x + 2 \therefore 2^{x+1}\le i<2^{x+2} ∴2x+1≤i<2x+2
2 × i 2 ≤ i ≤ 2 x + 2 2\times \dfrac{i}{2}\le i\le2^{x+2} 2×2i≤i≤2x+2
证毕。
因此可以 O ( n ) O(n) O(n) 预处理对数数组。
然后 O ( 1 ) O(1) O(1) 实现区间查询。
附一个RMQ。
#define il inline
struct RMQ{
int f[N][20],b[N];//pay attention init f[i][0]
il void init(int n){
for(int i=2;i<=n;i++) //pre deal with
b[i]=b[i>>1]+1; //注意从2开始
for(int j=1;j<=b[n];j++)
for(int i=1;i+(1<<j)-1<=n;i++)
f[i][j]=max(f[i][j-1],f[i+(1<<j-1)][j-1]);
}
il int que(int l,int r){
int x=b[r-l+1];
return max(f[l][x],f[r-(1<<x)+1][x]);
}
}rm;
边栏推荐
- JVM命令之- jmap:导出内存映像文件&内存使用情况
- SQL Server 2008 各种DateTime的取值范围
- MySQL performance_ Schema common performance diagnosis query
- Rk3399 platform development series explanation (interruption) 13.10, workqueue work queue
- QT console output in GUI applications- Console output in a Qt GUI app?
- 如何在Touch Designer 2022版中设置解决Leap Motion不识别的问题?
- 【FPGA教程案例13】基于vivado核的CIC滤波器设计与实现
- 老板总问我进展,是不信任我吗?(你觉得呢)
- Deep clustering: joint optimization of depth representation learning and clustering
- How to improve website weight
猜你喜欢
The solution of a simple algebraic problem
老板总问我进展,是不信任我吗?(你觉得呢)
可极大提升编程思想与能力的书有哪些?
Jstat of JVM command: View JVM statistics
苹果cms V10模板/MXone Pro自适应影视电影网站模板
laravel 使用腾讯云 COS5全教程
If you don't know these four caching modes, dare you say you understand caching?
JVM命令之- jmap:导出内存映像文件&内存使用情况
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
Red hat install kernel header file
随机推荐
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
Deep clustering: joint optimization of depth representation learning and clustering
3531. 哈夫曼树
On the discrimination of "fake death" state of STC single chip microcomputer
MySQL performance_ Schema common performance diagnosis query
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
JVM monitoring and diagnostic tools - command line
Understand the deserialization principle of fastjson for generics
[daily training -- Tencent selected 50] 292 Nim games
The boss always asks me about my progress. Don't you trust me? (what do you think)
话说SQLyog欺骗了我!
Jmeter自带函数不够用?不如自己动手开发一个
Ten stages of becoming a Senior IC Design Engineer. What stage are you in now?
JVM命令之 jstack:打印JVM中线程快照
从“跑分神器”到数据平台,鲁大师开启演进之路
Interview questions and salary and welfare of Shanghai byte
linear regression
Cloud acceleration helps you effectively solve attack problems!
深度聚类:将深度表示学习和聚类联合优化