Skip to content

Commit ed93a53

Browse files
committed
nits
1 parent 5f79eeb commit ed93a53

3 files changed

Lines changed: 22 additions & 27 deletions

File tree

library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33
//! @code
44
//! RollbackUF uf(n);
55
//! vector<int> hist;
6-
//! pq_updates pq([&](auto upd) {
6+
//! pq_updates pq([&](H& upd) {
77
//! hist.push_back(uf.time());
88
//! uf.join(upd.first, upd.second);
99
//! }, [&]() {
1010
//! uf.rollback(hist.back());
1111
//! hist.pop_back();
12-
//! }, pair<int, int>{});
12+
//! });
1313
//! pq.push(pri, {u, v});
1414
//! @endcode
1515
//! @time O(n log n)
1616
//! @space O(n)
17-
template<class F, class G, class H> struct pq_updates {
18-
F update;
17+
using H = pii;
18+
template<class F, class G> struct pq_updates {
19+
F upd;
1920
G undo;
2021
vector<pair<multimap<int, int>::iterator, H>> st, buf;
2122
multimap<int, int> mp;
22-
pq_updates(F update, G undo, H):
23-
update(update), undo(undo) {}
23+
pq_updates(F upd, G undo): upd(upd), undo(undo) {}
24+
void push(int pri, H upd_params) {
25+
upd(upd_params);
26+
st.emplace_back(mp.emplace(pri, sz(st)), upd_params);
27+
}
2428
void pop() {
2529
buf.clear();
2630
int t = sz(st) - 1;
@@ -37,12 +41,8 @@ template<class F, class G, class H> struct pq_updates {
3741
st.pop_back();
3842
mp.erase(buf[0].first);
3943
rep(i, t, sz(st)) {
40-
update(st[i].second);
44+
upd(st[i].second);
4145
st[i].first->second = i;
4246
}
4347
}
44-
void push(int pri, H upd_params) {
45-
update(upd_params);
46-
st.emplace_back(mp.emplace(pri, sz(st)), upd_params);
47-
}
4848
};

tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@ int main() {
2020
cin >> n >> l;
2121
vi arr(n);
2222
rep(i, 0, n) cin >> arr[i];
23-
vector<int> updates;
2423
stack_with_get_max stm;
25-
pq_updates pq([&](int id) { stm.join(updates[id]); },
26-
[&]() { stm.undo(); }, int{});
24+
pq_updates pq([&](pii id) { stm.join(id.first); },
25+
[&]() { stm.undo(); });
2726
int pri = (n - l) / 2;
28-
rep(i, 0, l) {
29-
updates.push_back(arr[i]);
30-
pq.push(pri--, size(updates) - 1);
31-
}
27+
rep(i, 0, l) { pq.push(pri--, {arr[i], arr[i]}); }
3228
cout << stm.get_max();
3329
rep(i, l, n) {
34-
updates.push_back(arr[i]);
35-
pq.push(pri--, size(updates) - 1);
30+
pq.push(pri--, {arr[i], arr[i]});
3631
pq.pop();
3732
cout << " " << stm.get_max();
3833
}

tests/library_checker_aizu_tests/handmade_tests/pq_updates.test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ int main() {
77
for (int max_capacity = 1; max_capacity <= 50;
88
max_capacity++) {
99
rep(pattern, 0, 5) {
10-
vi ds_history;
11-
auto update = [&](int id) {
10+
vector<pii> ds_history;
11+
auto update = [&](pii id) {
1212
ds_history.push_back(id);
1313
};
1414
auto undo = [&]() { ds_history.pop_back(); };
15-
pq_updates solver(update, undo, int{});
15+
pq_updates solver(update, undo);
1616
map<pair<int, int>, int> naive_mp;
1717
int upd_id_counter = 0;
1818
rep(op, 0, 200) {
@@ -28,19 +28,19 @@ int main() {
2828
else if (pattern == 3)
2929
pri = (op % 2 == 0) ? 1 : 2;
3030
else pri = rnd(1, 100);
31-
solver.push(pri, upd_id);
31+
solver.push(pri, {upd_id, upd_id});
3232
naive_mp[{pri, upd_id}] = upd_id;
3333
} else {
3434
solver.pop();
3535
auto max_it = prev(end(naive_mp));
3636
naive_mp.erase(max_it);
3737
}
38-
vi active_ds = ds_history;
38+
vector<pii> active_ds = ds_history;
3939
sort(all(active_ds));
40-
vi active_naive(sz(naive_mp));
40+
vector<pii> active_naive(sz(naive_mp));
4141
int i = 0;
4242
for (auto [key, id] : naive_mp)
43-
active_naive[i++] = id;
43+
active_naive[i++] = {id, id};
4444
sort(all(active_naive));
4545
assert(active_ds == active_naive);
4646
}

0 commit comments

Comments
 (0)