diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 21:17:29 +0100 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 21:17:29 +0100 |
| commit | 1880ccb6d85c6eb79e724593457877bab431951c (patch) | |
| tree | 23eddd5bd0b29b3024e170a5ef9023eda9226ab5 /content/datastructures | |
| parent | e95f59debd69ee7d45d5c966ce466d23264e1c3c (diff) | |
get rid of all() and sz()
Diffstat (limited to 'content/datastructures')
| -rw-r--r-- | content/datastructures/lichao.cpp | 5 | ||||
| -rw-r--r-- | content/datastructures/monotonicConvexHull.cpp | 9 | ||||
| -rw-r--r-- | content/datastructures/persistent.cpp | 36 | ||||
| -rw-r--r-- | content/datastructures/sparseTable.cpp | 4 | ||||
| -rw-r--r-- | content/datastructures/sparseTableDisjoint.cpp | 2 | ||||
| -rw-r--r-- | content/datastructures/treap.cpp | 2 |
6 files changed, 29 insertions, 29 deletions
diff --git a/content/datastructures/lichao.cpp b/content/datastructures/lichao.cpp index c20c61d..bdbf5f9 100644 --- a/content/datastructures/lichao.cpp +++ b/content/datastructures/lichao.cpp @@ -1,5 +1,6 @@ vector<ll> xs; // IMPORTANT: Initialize before constructing! -int findX(int i) { return lower_bound(all(xs), i) - begin(xs); } +int findX(int i) { + return ranges::lower_bound(xs, i) - begin(xs); } struct Fun { // Default: Linear function. Change as needed. ll m, c; @@ -11,7 +12,7 @@ struct Lichao { static constexpr Fun id = {0, INF}; // {0, -INF} int n, cap; vector<Fun> seg; - Lichao() : n(sz(xs)), cap(2 << __lg(n)), seg(2 * cap, id) {} + Lichao() : n(ssize(xs)), cap(2 << __lg(n)), seg(2 * cap, id) {} void _insert(Fun f, int l, int r, int i) { while (i < 2 * cap) { diff --git a/content/datastructures/monotonicConvexHull.cpp b/content/datastructures/monotonicConvexHull.cpp index 2bdeccf..295acc4 100644 --- a/content/datastructures/monotonicConvexHull.cpp +++ b/content/datastructures/monotonicConvexHull.cpp @@ -12,15 +12,14 @@ struct Envelope { } void add(ll m, ll b) { - while (sz(ls) > 1 && bad(ls.end()[-2], ls.back(), {m, b})) { - ls.pop_back(); - } + while (ssize(ls) > 1 + && bad(ls.end()[-2], ls.back(), {m,b})) ls.pop_back(); ls.push_back({m, b}); - ptr = min(ptr, (int)sz(ls) - 1); + ptr = min(ptr, (int)ssize(ls) - 1); } ll query(ll x) { - while (ptr < sz(ls)-1 && ls[ptr + 1](x) < ls[ptr](x)) ptr++; + while (ptr < ssize(ls)-1 && ls[ptr+1](x) < ls[ptr](x)) ptr++; return ls[ptr](x); } }; diff --git a/content/datastructures/persistent.cpp b/content/datastructures/persistent.cpp index f26680d..9f38806 100644 --- a/content/datastructures/persistent.cpp +++ b/content/datastructures/persistent.cpp @@ -1,18 +1,18 @@ -template<typename T>
-struct persistent {
- int& time;
- vector<pair<int, T>> data;
-
- persistent(int& time, T value = {})
- : time(time), data(1, {2*time, value}) {}
-
- T get(int t) {
- return prev(upper_bound(all(data),pair{2*t+1, T{}}))->second;
- }
-
- int set(T value) {
- time++;
- data.push_back({2*time, value});
- return time;
- }
-};
+template<typename T> +struct persistent { + int& time; + vector<pair<int, T>> data; + + persistent(int& time, T value = {}) + : time(time), data(1, {2*time, value}) {} + + T get(int t) { + return prev(ranges::upper_bound(data,pair{2*t+1, T{}}))->second; + } + + int set(T value) { + time++; + data.push_back({2*time, value}); + return time; + } +}; diff --git a/content/datastructures/sparseTable.cpp b/content/datastructures/sparseTable.cpp index 5e84236..44989ab 100644 --- a/content/datastructures/sparseTable.cpp +++ b/content/datastructures/sparseTable.cpp @@ -7,10 +7,10 @@ struct SparseTable { } void init(vector<ll> &vec) { - int n = sz(vec); + int n = ssize(vec); a = vec.data(); st.assign(__lg(n) + 1, vector<int>(n)); - iota(all(st[0]), 0); + iota(begin(st[0]), end(st[0]), 0); for (int j = 0; (2 << j) <= n; j++) { for (int i = 0; i + (2 << j) <= n; i++) { st[j + 1][i] = better(st[j][i] , st[j][i + (1 << j)]); diff --git a/content/datastructures/sparseTableDisjoint.cpp b/content/datastructures/sparseTableDisjoint.cpp index 39c7caa..bcf6b2e 100644 --- a/content/datastructures/sparseTableDisjoint.cpp +++ b/content/datastructures/sparseTableDisjoint.cpp @@ -8,7 +8,7 @@ struct DisjointST { } void init(vector<ll> &vec) { - int n = sz(vec); + int n = ssize(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) { diff --git a/content/datastructures/treap.cpp b/content/datastructures/treap.cpp index c5a60e9..bddfdb4 100644 --- a/content/datastructures/treap.cpp +++ b/content/datastructures/treap.cpp @@ -66,7 +66,7 @@ struct Treap { void insert(int i, ll val) { // and i = val auto [left, right] = split(root, i); treap.emplace_back(val); - left = merge(left, sz(treap) - 1); + left = merge(left, ssize(treap) - 1); root = merge(left, right); } |
