Skip to content

Commit b1896fa

Browse files
committed
this seems better
1 parent fec7ede commit b1896fa

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@
33
//! @code
44
//! RollbackUF uf(n);
55
//! vector<int> hist;
6-
//! vector<pair<int, int>> updates;
7-
//! pq_updates pq([&](int id) {
6+
//! pq_updates pq([&](auto upd) {
87
//! hist.push_back(uf.time());
9-
//! uf.join(updates[id].first, updates[id].second);
8+
//! uf.join(upd.first, upd.second);
109
//! }, [&]() {
1110
//! uf.rollback(hist.back());
1211
//! hist.pop_back();
13-
//! });
14-
//! updates.push_back({u, v});
15-
//! pq.push(pri, ssize(updates) - 1);
12+
//! }, pair<int, int>{});
13+
//! pq.push(pri, {u, v});
1614
//! @endcode
1715
//! @time O(n log n)
1816
//! @space O(n)
19-
template<class F, class G> struct pq_updates {
17+
template<class F, class G, class H> struct pq_updates {
2018
F update;
2119
G undo;
22-
vector<pair<multimap<int, int>::iterator, int>> st, buf;
20+
vector<pair<multimap<int, int>::iterator, H>> st, buf;
2321
multimap<int, int> mp;
24-
pq_updates(F update, G undo):
22+
pq_updates(F update, G undo, H):
2523
update(update), undo(undo) {}
2624
void pop() {
2725
buf.clear();
@@ -43,8 +41,8 @@ template<class F, class G> struct pq_updates {
4341
st[i].first->second = i;
4442
}
4543
}
46-
void push(int pri, int update_id) {
47-
update(update_id);
48-
st.emplace_back(mp.emplace(pri, sz(st)), update_id);
44+
void push(int pri, H upd_params) {
45+
update(upd_params);
46+
st.emplace_back(mp.emplace(pri, sz(st)), upd_params);
4947
}
5048
};

tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main() {
2323
vector<int> updates;
2424
stack_with_get_max stm;
2525
pq_updates pq([&](int id) { stm.join(updates[id]); },
26-
[&]() { stm.undo(); });
26+
[&]() { stm.undo(); }, int{});
2727
int pri = (n - l) / 2;
2828
rep(i, 0, l) {
2929
updates.push_back(arr[i]);

tests/library_checker_aizu_tests/handmade_tests/pq_updates.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main() {
1212
ds_history.push_back(id);
1313
};
1414
auto undo = [&]() { ds_history.pop_back(); };
15-
pq_updates solver(update, undo);
15+
pq_updates solver(update, undo, int{});
1616
map<pair<int, int>, int> naive_mp;
1717
int upd_id_counter = 0;
1818
rep(op, 0, 200) {

0 commit comments

Comments
 (0)