diff options
author | Anthony Wang | 2020-08-27 09:15:54 -0500 |
---|---|---|
committer | Anthony Wang | 2020-08-27 09:15:54 -0500 |
commit | 443cae7a515babd6312baf8519ecaf408bd5ae20 (patch) | |
tree | 2aa49ec0353e247cb135f6a3396480029a44bab1 | |
parent | 2e8cd40360bf6026b302deffb1adb4f5a3a33806 (diff) |
Update util.cpp
-rw-r--r-- | Miscellaneous/util.cpp | 10 |
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); } |