Skip to content

Commit d871599

Browse files
authored
Linear rmq golf idea (#218)
* golf * fix * revert
1 parent 5e1e5a8 commit d871599

2 files changed

Lines changed: 7 additions & 9 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]);

tests/.config/.cppcheck_suppression_list

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ constVariableReference:library_checker_aizu_tests/handmade_tests/dsu_size.test.c
5353
constVariableReference:../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp:34
5454
constVariablePointer:../kactl/content/numerical/FastFourierTransform.h:39
5555
cstyleCast:../kactl/content/numerical/FastFourierTransform.h:39
56-
derefInvalidIterator:../library/data_structures_[l,r]/linear_rmq.hpp:28
5756
derefInvalidIterator:library_checker_aizu_tests/handmade_tests/n_choose_k.test.cpp:13
5857
unreadVariable:library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp:12
5958
uninitvar:library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp:41

0 commit comments

Comments
 (0)