summaryrefslogtreecommitdiff
path: root/datastructures/lazyPropagation.cpp
diff options
context:
space:
mode:
authorYidi <noob999noob999@gmail.com>2024-06-24 22:16:45 +0200
committerYidi <noob999noob999@gmail.com>2024-06-24 22:16:45 +0200
commitbd1cf56201ea24cdb8808a3fc82f9e2128f1cef0 (patch)
tree3a7d00514368af5e605711524e0d1a7ab9bf9d10 /datastructures/lazyPropagation.cpp
parent500ac1e618410ac453fa4fe83e2348cad8c2418f (diff)
improve segtree lower_bound performance
Diffstat (limited to 'datastructures/lazyPropagation.cpp')
-rw-r--r--datastructures/lazyPropagation.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/datastructures/lazyPropagation.cpp b/datastructures/lazyPropagation.cpp
index 7af1a6a..7811220 100644
--- a/datastructures/lazyPropagation.cpp
+++ b/datastructures/lazyPropagation.cpp
@@ -65,13 +65,12 @@ struct SegTree {
ll lower_bound(int l, int r, T x) {
l += n, r += n;
push(l), push(r - 1);
- vector<int> a, st;
+ int a[32] = {}, lp = 0, rp = 32;
for (; l < r; l /= 2, r /= 2) {
- if (l&1) a.push_back(l++);
- if (r&1) st.push_back(--r);
+ if (l&1) a[lp++] = l++;
+ if (r&1) a[--rp] = --r;
}
- a.insert(a.end(), st.rbegin(), st.rend());
- for (int i : a) if (tree[i] >= x) { // Modify this
+ for (int i : a) if (i != 0 && tree[i] >= x) { // Modify this
while (i < n) {
push_down(i);
if (tree[2 * i] >= x) i = 2 * i; // And this