aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-08-27 09:15:54 -0500
committerAnthony Wang2020-08-27 09:15:54 -0500
commit443cae7a515babd6312baf8519ecaf408bd5ae20 (patch)
tree2aa49ec0353e247cb135f6a3396480029a44bab1
parent2e8cd40360bf6026b302deffb1adb4f5a3a33806 (diff)
Update util.cpp
-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);
}