summaryrefslogtreecommitdiff
path: root/datastructures/lazyPropagation1.cpp
diff options
context:
space:
mode:
authorNoobie99 <noob999noob999@gmail.com>2023-02-16 20:34:47 +0100
committerNoobie99 <noob999noob999@gmail.com>2023-02-16 20:34:47 +0100
commit3acf0a0820da8c7357f381ac3c2a4be3bee08184 (patch)
tree3a8363d3a66c508fda16c9be38114656024d0f63 /datastructures/lazyPropagation1.cpp
parent48f36b5c91b3dd4a5c43390ce14f1a7e05174929 (diff)
Improved Lazy Segment Tree
Diffstat (limited to 'datastructures/lazyPropagation1.cpp')
-rw-r--r--datastructures/lazyPropagation1.cpp49
1 files changed, 0 insertions, 49 deletions
diff --git a/datastructures/lazyPropagation1.cpp b/datastructures/lazyPropagation1.cpp
deleted file mode 100644
index c1ffcf0..0000000
--- a/datastructures/lazyPropagation1.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-int h; // = __lg(2*n)
-//a neutral value for the update:
-constexpr ll updateFlag = 0;
-vector<ll> d(N, updateFlag);
-
-void apply(int p, ll value) {
- tree[p] += value;
- if (p < sz(tree)/2) d[p] += value;
-}
-
-void build(int p) {
- p >>= __builtin_ctzll(p);
- while (p > 1) {
- p/=2;
- tree[p] = max(tree[2*p], tree[2*p+1]) + d[p];
-}}
-
-void push(int p) {
- for (int s = h; s > 0; s--) {
- int i = p >> s;
- if (d[i] != updateFlag) {
- apply(2*i , d[i]);
- apply(2*i+1, d[i]);
- d[i] = updateFlag;
-}}}
-
-void update(int l, int r, ll value) { // data[l..r)+=value
- l += sz(tree)/2, r += sz(tree)/2;
- int l0 = l, r0 = r;
- for (; l < r; l /= 2, r /= 2) {
- if (l&1) apply(l++, value);
- if (r&1) apply(--r, value);
- }
- build(l0);
- build(r0 - 1);
-}
-
-ll query(int l, int r) { // max[l..r)
- l += sz(tree)/2, r += sz(tree)/2;
- push(l);
- push(r - 1);
- ll res = query_default;
- for (; l < r; l /= 2, r /= 2) {
- if (l&1) res = max(res, tree[l++]);
- if (r&1) res = max(tree[--r], res);
- }
- return res;
-}
-