struct qst {
int r, bh;
};
int ans[MAXN];
vector <qst> q[MAXN]; // 根据 l 桶排,这里没有给出代码
int a[MAXN], fa[MAXN], sta[MAXN], tp;
// fa 记录向前连边的位置
int fd(int x) { // 路径压缩
int y = x;
while (fa[y] != y) {
y = fa[y];
}
while (fa[x] != x) {
int fax = fa[x];
fa[x] = y;
x = fax;
}
return y;
}
void sol() {
for (int i = 1; i <= n; i++) {
fa[i] = i;
}
for (int i = n; i >= 1; i--) {
while (tp && a[sta[tp]] >= a[i]) {
fa[sta[tp--]] = i;
}
sta[++tp] = i;
for (qst _ : q[i]) {
int r = _.r, bh = _.bh;
ans[bh] = a[fd(r)];
}
}
return;
}剪贴板
剪贴板 2qwwa4rf
剪贴板信息
剪贴板信息
- 收录
- 更新