diff --git a/library/data_structures_[l,r)/rmq.hpp b/library/data_structures_[l,r)/rmq.hpp index ffd78c72..5df5850b 100644 --- a/library/data_structures_[l,r)/rmq.hpp +++ b/library/data_structures_[l,r)/rmq.hpp @@ -23,7 +23,7 @@ template struct RMQ { } T query(int l, int r) { assert(l < r); - int lg = __lg(r - l); + int lg = bit_width(r - l + 0u) - 1; return op(dp[lg][l], dp[lg][r - (1 << lg)]); } }; diff --git a/library/data_structures_[l,r)/seg_tree_midpoint.hpp b/library/data_structures_[l,r)/seg_tree_midpoint.hpp index 933aaf02..41527639 100644 --- a/library/data_structures_[l,r)/seg_tree_midpoint.hpp +++ b/library/data_structures_[l,r)/seg_tree_midpoint.hpp @@ -1,6 +1,6 @@ #pragma once //! https://codeforces.com/blog/entry/112755 int split(int tl, int tr) { - int pw2 = 1 << __lg(tr - tl); + int pw2 = bit_floor(tr - tl + 0u); return min(tl + pw2, tr - pw2 / 2); } diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp index 4ac12cc4..91af8fa5 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/max_right.hpp @@ -1,6 +1,7 @@ void max_right(int l, int r, auto f) { for (T x = unit; l < r;) { - int u = l + n, v = __lg(min(u & -u, r - l)), + int u = l + n, + v = bit_width(min(u & -u, r - l) + 0u) - 1, m = l + (1 << v); if (T y = op(x, s[u >> v]); f(m, y)) l = m, x = y; else r = m - 1; diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp index 63672114..5d5e06c6 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/min_left.hpp @@ -1,6 +1,7 @@ void min_left(int l, int r, auto f) { for (T x = unit; l < r;) { - int u = r + n, v = __lg(min(u & -u, r - l)), + int u = r + n, + v = bit_width(min(u & -u, r - l) + 0u) - 1, m = r - (1 << v); if (T y = op(s[(u - 1) >> v], x); f(m, y)) r = m, x = y; diff --git a/library/data_structures_[l,r)/uncommon/deque_op.hpp b/library/data_structures_[l,r)/uncommon/deque_op.hpp index 73a96a70..e6a950cb 100644 --- a/library/data_structures_[l,r)/uncommon/deque_op.hpp +++ b/library/data_structures_[l,r)/uncommon/deque_op.hpp @@ -31,7 +31,7 @@ template struct deq { void pop_back() { if (empty(r)) { vector a(sz(l)); - transform(all(l), rbegin(a), + ranges::transform(l, rbegin(a), [](dt& x) { return x[0]; }); rebuild(a, sz(a) / 2); } @@ -44,7 +44,7 @@ template struct deq { void pop_front() { if (empty(l)) { vector a(sz(r)); - transform(all(r), begin(a), + ranges::transform(r, begin(a), [](dt& x) { return x[0]; }); rebuild(a, (sz(a) + 1) / 2); } @@ -58,9 +58,10 @@ template struct deq { partial_sum(sz_le + all(a), begin(presum) + sz_le, op); l.resize(sz_le); r.resize(sz(a) - sz_le); - transform(begin(a), begin(a) + sz_le, begin(presum), + ranges::transform(a | views::take(sz_le), presum, rbegin(l), [](T x, T y) { return dt{x, y}; }); - transform(sz_le + all(a), begin(presum) + sz_le, - begin(r), [](T x, T y) { return dt{x, y}; }); + ranges::transform(a | views::drop(sz_le), + presum | views::drop(sz_le), begin(r), + [](T x, T y) { return dt{x, y}; }); } }; diff --git a/library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp b/library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp index 192dac74..2c312d94 100644 --- a/library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp +++ b/library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp @@ -41,7 +41,7 @@ template struct pq_updates { auto it = remove_if(idx + all(upd_st), [&](auto& cur) { return cur.second->first >= lowest_pri; }); - reverse_copy(all(extra), it); + ranges::reverse_copy(extra, it); rep(i, idx, sz(upd_st)) ds.undo(); upd_st.pop_back(); mp.erase(prev(end(mp))); diff --git a/library/data_structures_[l,r]/disjoint_rmq.hpp b/library/data_structures_[l,r]/disjoint_rmq.hpp index 5df9ac63..fc105e79 100644 --- a/library/data_structures_[l,r]/disjoint_rmq.hpp +++ b/library/data_structures_[l,r]/disjoint_rmq.hpp @@ -27,7 +27,7 @@ template struct disjoint_rmq { } T query(int l, int r) { if (l == r) return dp[0][l]; - int lg = __lg(l ^ r); + int lg = bit_width((l ^ r) + 0u) - 1; return op(dp[lg][l], dp[lg][r]); } }; diff --git a/library/data_structures_[l,r]/rmq.hpp b/library/data_structures_[l,r]/rmq.hpp index b7d58b9f..d6014fce 100644 --- a/library/data_structures_[l,r]/rmq.hpp +++ b/library/data_structures_[l,r]/rmq.hpp @@ -23,7 +23,7 @@ template struct RMQ { } T query(int l, int r) { assert(l <= r); - int lg = __lg(r - l + 1); + int lg = bit_width(r - l + 1u) - 1; return op(dp[lg][l], dp[lg][r - (1 << lg) + 1]); } }; diff --git a/library/data_structures_[l,r]/seg_tree.hpp b/library/data_structures_[l,r]/seg_tree.hpp index e2a0a362..0b1661e5 100644 --- a/library/data_structures_[l,r]/seg_tree.hpp +++ b/library/data_structures_[l,r]/seg_tree.hpp @@ -17,7 +17,8 @@ //! @time O(n + q log n) //! @space O(n) int nxt(int& l, int r) { - int u = l, v = __lg(min(l & -l, r - l + 1)); + int u = l, + v = bit_width(min(l & -l, r - l + 1) + 0u) - 1; return l += 1 << v, u >> v; } template struct tree { diff --git a/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp b/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp index 286c19d4..a1eb7bff 100644 --- a/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp +++ b/library/data_structures_[l,r]/seg_tree_uncommon/max_right.hpp @@ -1,7 +1,8 @@ void max_right(int l, int r, auto f) { if (T x = s[l + n]; f(l, x)) for (l++; l <= r;) { - int u = l + n, v = __lg(min(u & -u, r - l + 1)), + int u = l + n, + v = bit_width(min(u & -u, r - l + 1) + 0u) - 1, m = l + (1 << v) - 1; if (T y = op(x, s[u >> v]); f(m, y)) l = m + 1, x = y; diff --git a/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp b/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp index d52d401d..7be67857 100644 --- a/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp +++ b/library/data_structures_[l,r]/seg_tree_uncommon/min_left.hpp @@ -1,7 +1,8 @@ int min_left(int l, int r, auto f) { if (T x = s[r + n]; f(r, x)) for (r--; l <= r;) { - int u = r + 1 + n, v = __lg(min(u & -u, r - l + 1)), + int u = r + 1 + n, + v = bit_width(min(u & -u, r - l + 1) + 0u) - 1, m = r - (1 << v) + 1; if (T y = op(s[(u - 1) >> v], x); f(m, y)) r = m - 1, x = y; diff --git a/library/dsu/range_parallel_dsu.hpp b/library/dsu/range_parallel_dsu.hpp index d18b4e91..2114eb3c 100644 --- a/library/dsu/range_parallel_dsu.hpp +++ b/library/dsu/range_parallel_dsu.hpp @@ -9,7 +9,7 @@ struct rp_dsu { vector dsus; rp_dsu(int n): dsus(bit_width(n + 0u), DSU(n)) {} void join(int u, int v, int len, auto f) { - int i = __lg(len); + int i = bit_width(len + 0u) - 1; join(u, v, f, i); join(u + len - (1 << i), v + len - (1 << i), f, i); } diff --git a/library/flow/hungarian.hpp b/library/flow/hungarian.hpp index 3e76b777..05b05a01 100644 --- a/library/flow/hungarian.hpp +++ b/library/flow/hungarian.hpp @@ -1,7 +1,7 @@ #pragma once //! https://e-maxx.ru/algo/assignment_hungary //! @code -//! vector cost(n+1,vector(m+1,(ll)0)); +//! vector cost(n+1,vector(m+1,ll(0))); //! auto [min_weight, l_to_r] = hungarian(cost); //! @endcode //! cost[i][j] = edge weight, 1<=i<=n<=m; 1<=j<=m diff --git a/library/graphs/mst.hpp b/library/graphs/mst.hpp index d8261dec..0e6ea834 100644 --- a/library/graphs/mst.hpp +++ b/library/graphs/mst.hpp @@ -11,9 +11,8 @@ pair mst(const vector>& w_eds, int n) { vi order(sz(w_eds)); iota(all(order), 0); - ranges::sort(order, [&](int i, int j) { - return w_eds[i][2] < w_eds[j][2]; - }); + ranges::sort(order, {}, + [&](int i) { return w_eds[i][2]; }); DSU dsu(n); vi ids; ll cost = 0; diff --git a/library/math/matrix_related/solve_linear_mod.hpp b/library/math/matrix_related/solve_linear_mod.hpp index 55b79be8..b82855ab 100644 --- a/library/math/matrix_related/solve_linear_mod.hpp +++ b/library/math/matrix_related/solve_linear_mod.hpp @@ -17,12 +17,12 @@ struct solve_linear_mod { int n = sz(mat), m = sz(mat[0]); rep(i, 0, n) mat[i].push_back(rhs[i]); tie(rank, det) = row_reduce(mat, m); - if (any_of(rank + all(mat), + if (ranges::any_of(mat | views::drop(rank), [](vi& v) { return v.back(); })) return; sol.resize(m); int j = 0; - for_each(begin(mat), begin(mat) + rank, [&](vi& v) { + ranges::for_each(mat | views::take(rank), [&](vi& v) { while (!v[j]) j++; sol[j] = v.back(); }); diff --git a/library/strings/suffix_array/find/find_string_bs_fast.hpp b/library/strings/suffix_array/find/find_string_bs_fast.hpp index 86014517..a543c21a 100644 --- a/library/strings/suffix_array/find/find_string_bs_fast.hpp +++ b/library/strings/suffix_array/find/find_string_bs_fast.hpp @@ -10,16 +10,16 @@ match find_str_fast(const T& t) { if (int lcp_len = s_l == n ? 0 : len_lcp(s_l, i); lcp_len != s_len) return (lcp_len < s_len) ^ (cmp_sufs(s_l, i) < 0); - auto [it_s, it_t] = - mismatch(i + s_len + all(s), s_len + all(t)); + auto [it_s, it_t] = ranges::mismatch( + s | views::drop(i + s_len), t | views::drop(s_len)); s_l = i, s_len = it_t - begin(t); return lexicographical_compare(it_s, end(s), it_t, end(t)); }; - int sa_le = lower_bound(all(sa), 0, cmp) - begin(sa), + int sa_le = ranges::lower_bound(sa, 0, cmp) - begin(sa), sa_ri = sa_le; if (s_len == sz(t)) - sa_ri = lower_bound(sa_le + all(sa), 0, + sa_ri = ranges::lower_bound(sa | views::drop(sa_le), 0, [&](int i, int) -> bool { return len_lcp(s_l, i) >= sz(t); }) - diff --git a/library/strings/suffix_array/find/find_substring.hpp b/library/strings/suffix_array/find/find_substring.hpp index e882ac98..aff5b30a 100644 --- a/library/strings/suffix_array/find/find_substring.hpp +++ b/library/strings/suffix_array/find/find_substring.hpp @@ -16,10 +16,11 @@ pii find_substr(int s_l, int s_r) { auto cmp = [&](int i, bool flip) -> bool { return flip ^ (len_lcp(i, s_l) < s_r - s_l); }; - int l = lower_bound(begin(sa), begin(sa) + sa_inv[s_l], - 0, cmp) - + int l = ranges::lower_bound( + sa | views::take(sa_inv[s_l]), 0, cmp) - begin(sa); - int r = lower_bound(sa_inv[s_l] + 1 + all(sa), 1, cmp) - + int r = ranges::lower_bound( + sa | views::drop(sa_inv[s_l] + 1), 1, cmp) - begin(sa); return {l, r}; } diff --git a/library/strings/wildcard_pattern_matching.hpp b/library/strings/wildcard_pattern_matching.hpp index fe2c531a..c30d91cf 100644 --- a/library/strings/wildcard_pattern_matching.hpp +++ b/library/strings/wildcard_pattern_matching.hpp @@ -25,7 +25,7 @@ vector wildcard_pattern_matching(const vl& s, int n = sz(s), m = sz(t); auto s_pws = make_powers(s); auto t_pws = make_powers(t); - for (auto& t_pw : t_pws) reverse(all(t_pw)); + for (auto& t_pw : t_pws) ranges::reverse(t_pw); vector res(3); rep(pw_hay, 0, 3) res[pw_hay] = conv(s_pws[pw_hay], t_pws[2 - pw_hay]); diff --git a/library/trees/uncommon/ladder_decomposition.hpp b/library/trees/uncommon/ladder_decomposition.hpp index ae1435b4..bc9e31e5 100644 --- a/library/trees/uncommon/ladder_decomposition.hpp +++ b/library/trees/uncommon/ladder_decomposition.hpp @@ -44,7 +44,7 @@ struct ladder { int kth_par(int u, int k) { assert(0 <= k && k <= d[u]); if (k == 0) return u; - int bit = __lg(k); + int bit = bit_width(k + 0u) - 1; u = jmp[bit][u], k -= (1 << bit); int i = idx[u], j = i + d[lad[i]] - d[u]; assert(lad[j] == u); diff --git a/library/trees/uncommon/linear_kth_par.hpp b/library/trees/uncommon/linear_kth_par.hpp index 5ca8eaba..f5224ce8 100644 --- a/library/trees/uncommon/linear_kth_par.hpp +++ b/library/trees/uncommon/linear_kth_par.hpp @@ -50,7 +50,8 @@ struct linear_kth_par { if (k == 0) return u; int anc_d = d[u] - k, bc = bit_ceil(k + 0u); int t = (tin[u] + bc / 2) & -bc; - int i = idx[jmp[t].at(__lg(d_tour[t] - anc_d))]; + int i = idx[jmp[t].at( + bit_width(d_tour[t] - anc_d + 0u) - 1)]; return lad[i + d[lad[i]] - anc_d]; } };