1
0
Fork 0

Update segtree_generic.cc

This commit is contained in:
Ariel 2024-03-07 17:15:15 +08:00 committed by GitHub
parent 485e97c412
commit 9fdcb9b47b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -7,11 +7,16 @@ private:
vector<info_type> d; vector<info_type> d;
vector<tag_type> b; vector<tag_type> b;
void pull(size_type p) {
d[p] = d[p * 2] + d[p * 2 + 1];
}
void push(size_type p) { void push(size_type p) {
d[p * 2].apply(b[p]), d[p * 2 + 1].apply(b[p]); d[p * 2].apply(b[p]), d[p * 2 + 1].apply(b[p]);
b[p * 2].apply(b[p]), b[p * 2 + 1].apply(b[p]); b[p * 2].apply(b[p]), b[p * 2 + 1].apply(b[p]);
b[p] = tag_type(); b[p] = tag_type();
} }
void set(size_type s, size_type t, size_type p, size_type x, const info_type& c) { void set(size_type s, size_type t, size_type p, size_type x, const info_type& c) {
if (s == t) { if (s == t) {
d[p] = c; d[p] = c;
@ -34,7 +39,7 @@ private:
push(p); push(p);
if (l <= m) range_apply(s, m, p * 2, l, r, c); if (l <= m) range_apply(s, m, p * 2, l, r, c);
if (r > m) range_apply(m + 1, t, p * 2 + 1, l, r, c); if (r > m) range_apply(m + 1, t, p * 2 + 1, l, r, c);
d[p] = d[p * 2] + d[p * 2 + 1]; pull(p);
} }
info_type range_query(size_type s, size_type t, size_type p, size_type l, size_type r) { info_type range_query(size_type s, size_type t, size_type p, size_type l, size_type r) {
@ -57,7 +62,7 @@ private:
int m = s + (t - s >> 1); int m = s + (t - s >> 1);
build(a, s, m, p * 2); build(a, s, m, p * 2);
build(a, m + 1, t, p * 2 + 1); build(a, m + 1, t, p * 2 + 1);
d[p] = d[p * 2] + d[p * 2 + 1]; pull(p);
} }
public: public:
segtree(size_type __max) : d(4 * __max), b(4 * __max), _max(__max - 1) {} segtree(size_type __max) : d(4 * __max), b(4 * __max), _max(__max - 1) {}