diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-04-28 03:26:45 +0200 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-04-28 03:26:45 +0200 |
| commit | d6d3b6183df2e1d40154f406916993f9b15b3cae (patch) | |
| tree | fce26b106de624759a36e5add64aabad62f95a55 /datastructures/sparseTableDisjoint.cpp | |
| parent | 2e0ba29cd0de1e88bed78a96f587613bcf3cc97c (diff) | |
improve sparse tables
Diffstat (limited to 'datastructures/sparseTableDisjoint.cpp')
| -rw-r--r-- | datastructures/sparseTableDisjoint.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/datastructures/sparseTableDisjoint.cpp b/datastructures/sparseTableDisjoint.cpp index 31e9025..dc5297a 100644 --- a/datastructures/sparseTableDisjoint.cpp +++ b/datastructures/sparseTableDisjoint.cpp @@ -1,5 +1,5 @@ struct DisjointST { - static constexpr ll neutral = 0 + static constexpr ll neutral = 0; vector<vector<ll>> dst; ll* a; @@ -7,16 +7,16 @@ struct DisjointST { return x + y; } - void init(vector<ll> *vec) { - int n = sz(*vec); - a = vec->data(); + void init(vector<ll> &vec) { + int n = sz(vec); + a = vec.data(); dst.assign(__lg(n) + 1, vector<ll>(n + 1, neutral)); for (int h = 0, l = 1; l <= n; h++, l *= 2) { for (int c = l; c < n + l; c += 2 * l) { for (int i = c; i < min(n, c + l); i++) - dst[h][i + 1] = combine(dst[h][i], vec->at(i)); + dst[h][i + 1] = combine(dst[h][i], vec[i]); for (int i = min(n, c); i > c - l; i--) - dst[h][i - 1] = combine(vec->at(i - 1), dst[h][i]); + dst[h][i - 1] = combine(vec[i - 1], dst[h][i]); }}} ll query(int l, int r) { |
