正文
增加 2 行删除 2 行
32 行未改动3334353637383940414 行未改动46474849505152535497 行未改动32 行未改动定义 $dp_{i,j}$ 为第 $j$ 个数向后 $2^i$ 个数的最大值,那么转移方程如下:$$st_{i,0}=a_i\\st_{i,j}=\max(st_{i,j-1},st_{i+2^{j-1},j-1})$$每次查询的时候,就是查下面这个式子:$$k=\lfloor \log_2(r-l+1)\rfloor\\\max(st_{l,k},st_{r-2^k+1,k})4 行未改动```cpp#include <bits/stdc++.h>#define endl '\n'using namespace std;const int N = 1e5 + 10;int n, m, a[N], lg2[N], st[N][22];void init() {lg2[0] = -1;for(int i = 1; i <= n; i++) lg2[i] = lg2[i / 2] + 1;97 行未改动32 行未改动3334353637383940414 行未改动46474849505152535497 行未改动32 行未改动定义 $dp_{i,j}$ 为第 $j$ 个数向后 $2^i$ 个数的最大值,那么转移方程如下:$$st_{i,0}=a_i\\st_{i,j}=\max(st_{i,j-1},st_{i+2^{j-1},j-1})$$每次查询的时候,就是查下面这个式子:$$k=\lfloor \log_2(r-l+1)\rfloor\\\max(st_{l,k},st_{r-2^k+1,k})4 行未改动```cpp#include <bits/stdc++.h>#define endl '\n'using namespace std;const int N = 1e5 + 10;int n, m, a[N], lg2[N], st[N][22];void init() {lg2[0] = -1;for(int i = 1; i <= n; i++) lg2[i] = lg2[i / 2] + 1;97 行未改动