From 5ab8a5088b729a9953b8dff1b2a985dc8fb2098b Mon Sep 17 00:00:00 2001 From: mzuenni Date: Mon, 27 Jun 2022 17:19:28 +0200 Subject: updated tcr --- datastructures/lazyPropagation2.cpp | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 datastructures/lazyPropagation2.cpp (limited to 'datastructures/lazyPropagation2.cpp') diff --git a/datastructures/lazyPropagation2.cpp b/datastructures/lazyPropagation2.cpp new file mode 100644 index 0000000..e90c671 --- /dev/null +++ b/datastructures/lazyPropagation2.cpp @@ -0,0 +1,50 @@ +void calc(int p, ll k) { + if (d[p] == updateFlag) tree[p] = tree[2*p] + tree[2*p+1]; + else tree[p] = d[p] * k; +} + +void apply(int p, ll value, int k) { + tree[p] = value * k; + if (p < sz(tree)/2) d[p] = value; +} + +void build(int l, int r) { + int k = 2; + for (l += sz(tree)/2, r += sz(tree)/2-1; l > 1; k <<= 1) { + l/=2, r/=2; + for (int i = r; i >= l; --i) calc(i, k); +}} + +void push(int l, int r) { + int s = h, k = 1 << (h-1); + for (l += sz(tree)/2, r += sz(tree)/2-1; s > 0; --s, k/=2) { + for (int i = l >> s; i <= r >> s; ++i) { + if (d[i] != updateFlag) { + apply(2*i , d[i], k); + apply(2*i+1, d[i], k); + d[i] = updateFlag; +}}}} + +void modify(int l, int r, ll value) { + if (value == updateFlag) return; + push(l, l + 1); + push(r - 1, r); + int l0 = l, r0 = r, k = 1; + for (l += sz(tree)/2, r += sz(tree)/2; l