当前位置:网站首页>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;
边栏推荐
- Ten stages of becoming a Senior IC Design Engineer. What stage are you in now?
- On the discrimination of "fake death" state of STC single chip microcomputer
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
- Deep clustering: joint optimization of depth representation learning and clustering
- @pathvariable 和 @Requestparam的详细区别
- Financial risk control practice - decision tree rule mining template
- 360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
- [daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
- The boss always asks me about my progress. Don't you trust me? (what do you think)
- Peripheral driver library development notes 43: GPIO simulation SPI driver
猜你喜欢

Jstack of JVM command: print thread snapshots in JVM

关于STC单片机“假死”状态的判别

每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)

Reading notes of Clickhouse principle analysis and Application Practice (6)

The solution of a simple algebraic problem

话说SQLyog欺骗了我!

为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾

Mac version PHP installed Xdebug environment (M1 version)

高并发大流量秒杀方案思路

@Detailed differences between pathvariable and @requestparam
随机推荐
laravel 使用腾讯云 COS5全教程
PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
@pathvariable 和 @Requestparam的详细区别
How to improve website weight
Nvisual network visualization
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
【SQL实战】一条SQL统计全国各地疫情分布情况
QT console output in GUI applications- Console output in a Qt GUI app?
苹果cms V10模板/MXone Pro自适应影视电影网站模板
Say sqlyog deceived me!
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
计算模型 FPS
Peripheral driver library development notes 43: GPIO simulation SPI driver
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
VScode进行代码补全
Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
You don't know the complete collection of recruitment slang of Internet companies
Digital IC interview summary (interview experience sharing of large manufacturers)
linear regression
ML's shap: Based on the adult census income binary prediction data set (whether the predicted annual income exceeds 50K), use the shap decision diagram combined with the lightgbm model to realize the