From 443cae7a515babd6312baf8519ecaf408bd5ae20 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 27 Aug 2020 09:15:54 -0500 Subject: Update util.cpp --- Miscellaneous/util.cpp | 10 +++++----- 1 file 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 // Coordinate compression +template // Coordinate compression void compress(BidirectionalIterator first, BidirectionalIterator last) { - vector 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> 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); } -- cgit v1.2.3-70-g09d2