aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Miscellaneous/util.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Miscellaneous/util.cpp b/Miscellaneous/util.cpp
index d903c1e..2816c2b 100644
--- a/Miscellaneous/util.cpp
+++ b/Miscellaneous/util.cpp
@@ -1,7 +1,7 @@
-template <class BidirectionalIterator> // Coordinate compression
+template<typename BidirectionalIterator> // Coordinate compression
void compress(BidirectionalIterator first, BidirectionalIterator last) {
- vector<auto> tmp(first, last);
- sort(tmp.begin(), tmp.end());
- tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
- for (auto it = first; it != last; it++) *it = lower_bound(tmp.begin(), tmp.end(), *it) - tmp.begin();
+ vector<pair<BidirectionalIterator, int>> tmp;
+ for (auto it = first; it != last; ++it) tmp.emplace_back(*it, it-first);
+ sort(begin(tmp), end(tmp));
+ for (auto it = begin(tmp); it != end(tmp); ++it) (first+it->s) = it-begin(tmp);
}