当前位置:网站首页>RMQ interval maximum subscript query, interval maximum
RMQ interval maximum subscript query, interval maximum
2022-06-25 08:02:00 【Mfy's little brother 1】
RMQ Interval maximum subscript query
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;
The best value of the interval
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]);
}
边栏推荐
- Import data into Matlab
- Vscode is good, but I won't use it again
- 现在通过开户经理发的开户链接股票开户安全吗?
- 产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具
- Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
- 电子学:第012课——实验 13:烧烤 LED
- Matlab code format one click beautification artifact
- Machine learning notes linear regression of time series
- Analysis of kinsing dual platform mining family virus
- 不怕百战失利,就怕灰心丧气
猜你喜欢
剑指offer刷题(简单等级)
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
电子学:第012课——实验 13:烧烤 LED
剑指offer刷题(中等等级)
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
Debugging mipi-dsi screen based on stm32mp157
Requirements for Power PCB circuit board design 2021-11-09
C disk drives, folders and file operations
CAN总线工作状况和信号质量“体检”
Modular programming of LCD1602 LCD controlled by single chip microcomputer
随机推荐
C examples of using colordialog to change text color and fontdialog to change text font
产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具
FFT【模板】
Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
年后求职找B端产品经理?差点把自己坑惨了......
@The difference between resource and @autowired annotation, why recommend @resource?
将数据导入到MATLAB
This article uses pytorch to build Gan model!
50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool
Vscode is good, but I won't use it again
C#中如何调整图像大小
Importer des données dans MATLAB
剑指offer刷题(简单等级)
Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries
FM信号、调制信号和载波
Do you know why the PCB produces tin beads? 2021-09-30
Cifar-10 dataset application: quick start data enhancement method mixup significantly improves image recognition accuracy
Advantages and differences of three kinds of vias in PCB 2021-10-27
Mining microbial dark matter -- a new idea
Ph中和过程建模