diff --git a/library/data_structures_[l,r]/linear_rmq.hpp b/library/data_structures_[l,r]/linear_rmq.hpp index c48844f4..52d5d965 100644 --- a/library/data_structures_[l,r]/linear_rmq.hpp +++ b/library/data_structures_[l,r]/linear_rmq.hpp @@ -19,17 +19,16 @@ template struct linear_rmq { vi in, asc, head; linear_rmq(const vector& a, F cmp): n(sz(a)), a(a), cmp(cmp), in(n), asc(n), head(n + 1) { - vi st{-1}; + vi st(n + 1, -1); + int t = 0; rep(i, 0, n + 1) { int prev = 0; - while (sz(st) > 1 && - (i == n || !cmp(a[st.back()], a[i]))) { - head[prev] = st.back(); - auto j = end(st)[-2] + 1u, k = bit_floor(i ^ j); - in[st.back()] = prev = i & -k, asc[j] |= k; - st.pop_back(); + while (t && (i == n || !cmp(a[st[t]], a[i]))) { + head[prev] = st[t]; + auto j = st[t - 1] + 1u, k = bit_floor(i ^ j); + in[st[t--]] = prev = i & -k, asc[j] |= k; } - st.push_back(head[prev] = i); + st[++t] = head[prev] = i; } rep(i, 1, n) asc[i] = (asc[i] | asc[i - 1]) & -(in[i] & -in[i]); diff --git a/tests/.config/.cppcheck_suppression_list b/tests/.config/.cppcheck_suppression_list index 3dc20270..4cdfb366 100644 --- a/tests/.config/.cppcheck_suppression_list +++ b/tests/.config/.cppcheck_suppression_list @@ -53,7 +53,6 @@ constVariableReference:library_checker_aizu_tests/handmade_tests/dsu_size.test.c constVariableReference:../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp:34 constVariablePointer:../kactl/content/numerical/FastFourierTransform.h:39 cstyleCast:../kactl/content/numerical/FastFourierTransform.h:39 -derefInvalidIterator:../library/data_structures_[l,r]/linear_rmq.hpp:28 derefInvalidIterator:library_checker_aizu_tests/handmade_tests/n_choose_k.test.cpp:13 unreadVariable:library_checker_aizu_tests/handmade_tests/permutation_tree_small.test.cpp:12 uninitvar:library_checker_aizu_tests/handmade_tests/seg_tree_find_small.test.cpp:41