当前位置:网站首页>RMQ区间最大值下标查询,区间最值
RMQ区间最大值下标查询,区间最值
2022-06-25 06:43:00 【mfy的1号小迷弟】
RMQ区间最大值下标查询
void init(int n) {
for (int i = 1; i <= n; i++) table[i][0] = i;
for (int j = 1; (1 << j) <= n; j++)
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
int x = table[i][j - 1], y = table[i + (1 << (j - 1))][j - 1];
table[i][j] = sum[x] > sum[y] ? x : y;
}
}
int query(int l, int r) {
int k = log2(r - l + 1);
int x = table[l][k], y = table[r - (1 << k) + 1][k];
return sum[x] > sum[y] ? x : y;
区间最值
void ST(int n) {
for (int i = 1; i <= n; i++)
dp[i][0] = A[i];
for (int j = 1; (1 << j) <= n; j++) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
}
}
}
int RMQ(int l, int r) {
int k = 0;
while ((1 << (k + 1)) <= r - l + 1) k++;
return max(dp[l][k], dp[r - (1 << k) + 1][k]);
}
边栏推荐
- ffmpeg+SDL2实现音频播放
- Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
- Mysql面试-执行sql响应比较慢,排查思路。
- Analysis and utilization of Microsoft Office Word remote command execution vulnerability (cve-2022-30190)
- 如何用svn新建属于自己的分支
- 机器学习笔记 - 时间序列的线性回归
- [little knowledge] PCB proofing process
- 417-二叉树的层序遍历1(102. 二叉树的层序遍历、107.二叉树的层次遍历 II、199.二叉树的右视图、637.二叉树的层平均值)
- 用函数的递归来解决几道有趣的题
- 单位转换-毫米转像素-像素转毫米
猜你喜欢

CAN总线工作状况和信号质量“体检”

差点被这波Handler 面试连环炮带走~

权限、认证系统相关名词概念

饮食干预减轻癌症治疗相关症状和毒性

Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC

One "stone" and two "birds", PCA can effectively improve the dilemma of missing some ground points under the airborne lidar forest

SCM Project Training

机器学习笔记 - 时间序列的线性回归

50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool

STL tutorial 4- input / output stream and object serialization
随机推荐
单位转换-毫米转像素-像素转毫米
Cifar-10 dataset application: quick start data enhancement method mixup significantly improves image recognition accuracy
Invalid Navicat scheduled task
Five causes of PCB board deformation and six solutions 2021-10-08
Share the process requirements for single-layer flexible circuit board
How much do you know about electronic components on PCB?
C control refresh
LeetCode_哈希表_中等_454.四数相加 II
1464. maximum product of two elements in an array
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
php入门基础记录
How to select lead-free and lead-free tin spraying for PCB? 2021-11-16
Technology blog | how to communicate using SSE
NSIS silent installation vs2013 runtime
Atlas conference vulnerability analysis collection
差点被这波Handler 面试连环炮带走~
Manufacturing process of PCB 2021-10-11
Anaconda based module installation and precautions
navicat定时任务无效
环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用