Skip to content

Commit 0eb9e4e

Browse files
committed
another golf
1 parent 6d7cbf7 commit 0eb9e4e

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ template<class F, class G> struct pq_updates {
3030
int l = sz(st), r = l;
3131
for (auto& [_, i] : mp) {
3232
l = min(l, i);
33-
if (i != --r) {
34-
swap(st[i], st[r]);
35-
swap(st[i].first->second, i);
36-
}
33+
swap(st[i], st[--r]);
34+
swap(st[i].first->second, i);
3735
if (r - l <= sz(st) - r) break;
3836
}
3937
rep(i, l, sz(st)) undo();

tests/library_checker_aizu_tests/handmade_tests/pq_updates.test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#define PROBLEM \
22
"https://onlinejudge.u-aizu.ac.jp/problems/ITP1_1_A"
3+
// swapping iterators in as part of `swap(st[i], st[--r]);`
4+
// leads to RTE with debug mode :(
5+
#undef _GLIBCXX_DEBUG
36
#include "../template.hpp"
47
#include "../../../library/contest/random.hpp"
58
#include "../../../library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp"

0 commit comments

Comments
 (0)