diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/implicit.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/implicit.hpp index 3d2648c4..cdd51142 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/implicit.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/implicit.hpp @@ -42,7 +42,7 @@ template struct implicit_seg_tree { int v) { if (r <= tl || tr <= l) return; if (l <= tl && tr <= r) return apply(add, v); - int tm = tl + (tr - tl) / 2; + int tm = midpoint(tl, tr); push(tl, tm, tr, v); update(l, r, add, tl, tm, tree[v].lch); update(l, r, add, tm, tr, tree[v].rch); @@ -55,7 +55,7 @@ template struct implicit_seg_tree { dt query(int l, int r, int tl, int tr, int v) { if (r <= tl || tr <= l) return unit; if (l <= tl && tr <= r) return tree[v].num; - int tm = tl + (tr - tl) / 2; + int tm = midpoint(tl, tr); push(tl, tm, tr, v); return op(query(l, r, tl, tm, tree[v].lch), query(l, r, tm, tr, tree[v].rch)); diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/kth_smallest_query.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/kth_smallest_query.hpp index 09aff8cc..1aeca186 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/kth_smallest_query.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/kth_smallest_query.hpp @@ -25,7 +25,7 @@ struct kth_smallest { } int query(int k, int tl, int tr, int vl, int vr) { if (tr - tl == 1) return tl; - int tm = tl + (tr - tl) / 2; + int tm = midpoint(tl, tr); int cnt_l = pst.tree[pst.tree[vr].lch].sum - pst.tree[pst.tree[vl].lch].sum; if (cnt_l >= k) diff --git a/library/data_structures_[l,r)/seg_tree_uncommon/persistent.hpp b/library/data_structures_[l,r)/seg_tree_uncommon/persistent.hpp index 151cda92..f59ad519 100644 --- a/library/data_structures_[l,r)/seg_tree_uncommon/persistent.hpp +++ b/library/data_structures_[l,r)/seg_tree_uncommon/persistent.hpp @@ -30,7 +30,7 @@ struct PST { tree.emplace_back(tree[v].sum + change, 0, 0); return sz(tree) - 1; } - int tm = tl + (tr - tl) / 2; + int tm = midpoint(tl, tr); int lch = tree[v].lch; int rch = tree[v].rch; if (idx < tm) lch = update(idx, change, tl, tm, lch); @@ -45,7 +45,7 @@ struct PST { ll query(int l, int r, int tl, int tr, int v) { if (v == 0 || r <= tl || tr <= l) return 0; if (l <= tl && tr <= r) return tree[v].sum; - int tm = tl + (tr - tl) / 2; + int tm = midpoint(tl, tr); return query(l, r, tl, tm, tree[v].lch) + query(l, r, tm, tr, tree[v].rch); } diff --git a/library/math/num_distinct_subsequences.hpp b/library/math/num_distinct_subsequences.hpp index 2ff86242..301c10be 100644 --- a/library/math/num_distinct_subsequences.hpp +++ b/library/math/num_distinct_subsequences.hpp @@ -9,12 +9,11 @@ int num_subsequences(const vi& a, int mod) { rep(i, 0, sz(a)) { int& cur = dp[i + 1] = 2 * dp[i]; if (cur >= mod) cur -= mod; - auto it = last.find(a[i]); - if (it != end(last)) { - cur -= dp[it->second]; + auto [it, ins] = last.emplace(a[i], i); + if (!ins) { + cur -= dp[exchange(it->second, i)]; if (cur < 0) cur += mod; - it->second = i; - } else last[a[i]] = i; + } } return dp.back(); }