Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/data_structures_[l,r)/seg_tree_uncommon/implicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ template<int N> 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);
Expand All @@ -55,7 +55,7 @@ template<int N> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions library/math/num_distinct_subsequences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Loading