Skip to content

Commit 42760e8

Browse files
committed
golf
1 parent 5e1e5a8 commit 42760e8

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

library/data_structures_[l,r]/linear_rmq.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ template<class T, class F> struct linear_rmq {
1919
vi in, asc, head;
2020
linear_rmq(const vector<T>& a, F cmp):
2121
n(sz(a)), a(a), cmp(cmp), in(n), asc(n), head(n + 1) {
22-
vi st{-1};
22+
vi st(n + 1, -1);
23+
int t = 0;
2324
rep(i, 0, n + 1) {
2425
int prev = 0;
25-
while (sz(st) > 1 &&
26-
(i == n || !cmp(a[st.back()], a[i]))) {
27-
head[prev] = st.back();
28-
auto j = end(st)[-2] + 1u, k = bit_floor(i ^ j);
29-
in[st.back()] = prev = i & -k, asc[j] |= k;
30-
st.pop_back();
26+
while (t && (i == n || !cmp(a[st[t]], a[i]))) {
27+
head[prev] = st[t];
28+
auto j = st[t - 1] + 1u, k = bit_floor(i ^ j);
29+
in[st[t--]] = prev = i & -k, asc[j] |= k;
3130
}
32-
st.push_back(head[prev] = i);
31+
st[++t] = head[prev] = i;
3332
}
3433
rep(i, 1, n)
3534
asc[i] = (asc[i] | asc[i - 1]) & -(in[i] & -in[i]);

0 commit comments

Comments
 (0)