ll stmi[maxn][30], stmx[maxn][30];
void initst() {
for(int i = 0; i <= n; i++) stmi[i][0] = stmx[i][0] = cc[i];
for(int j = 1; (1<<j) <= n+1; j++) {
for(int i = 0; i+(1<<j)-1 <= n; i++) {
stmx[i][j] = max(stmx[i][j-1], stmx[i+(1<<(j-1))][j-1]);
stmi[i][j] = min(stmi[i][j-1], stmi[i+(1<<(j-1))][j-1]);
}
}
}
ll askmx(int l, int r) {
int k = log2(r-l+1);//一定要加log2
return max(stmx[l][k], stmx[r-(1<<k)+1][k]);
}
ll askmi(int l, int r) {
int k = log2(r-l+1);//一定要加log2
return min(stmi[l][k], stmi[r-(1<<k)+1][k]);
}
st表模板
最新推荐文章于 2024-07-18 17:22:15 发布