当前位置:网站首页>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;
边栏推荐
- Nvisual network visualization
- Career experience feedback to novice programmers
- 解决pod install报错:ffi is an incompatible architecture
- JVM命令之 jstat:查看JVM統計信息
- A freshman's summary of an ordinary student [I don't know whether we are stupid or crazy, but I know to run forward all the way]
- Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
- 【FPGA教程案例13】基于vivado核的CIC滤波器设计与实现
- mac版php装xdebug环境(m1版)
- 牙齿干细胞的存储问题(未完待续)
- [daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
猜你喜欢
搞懂fastjson 对泛型的反序列化原理
当我们谈论不可变基础设施时,我们在谈论什么
PowerPivot - DAX (function)
Interview questions and salary and welfare of Shanghai byte
Financial risk control practice - decision tree rule mining template
A very good JVM interview question article (74 questions and answers)
测试开发基础,教你做一个完整功能的Web平台之环境准备
Rk3399 platform development series explanation (WiFi) 5.53, hostapd (WiFi AP mode) configuration file description
外设驱动库开发笔记43:GPIO模拟SPI驱动
C note 13
随机推荐
JMeter's own functions are not enough? Why don't you develop one yourself
Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
高并发大流量秒杀方案思路
蚂蚁庄园安全头盔 7.8蚂蚁庄园答案
一个简单的代数问题的求解
【FPGA教程案例13】基于vivado核的CIC滤波器设计与实现
The boss always asks me about my progress. Don't you trust me? (what do you think)
980. Different path III DFS
POI excel export, one of my template methods
cf:C. Column Swapping【排序 + 模擬】
@Detailed differences between pathvariable and @requestparam
Classic questions about data storage
CMD permanently delete specified folders and files
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
如果不知道这4种缓存模式,敢说懂缓存吗?
yarn入门(一篇就够了)
测试开发基础,教你做一个完整功能的Web平台之环境准备
话说SQLyog欺骗了我!
苹果cms V10模板/MXone Pro自适应影视电影网站模板
10W word segmentation searches per second, the product manager raised another demand!!! (Collection)