From 03788f48be2634c36cd19ba25b0a851685b9c877 Mon Sep 17 00:00:00 2001 From: MZuenni Date: Wed, 30 Nov 2022 12:43:27 +0100 Subject: use all macro --- datastructures/segmentTree.cpp | 2 +- geometry/closestPair.cpp | 8 ++++---- geometry/convexHull.cpp | 20 ++++++++++---------- geometry/linesAndSegments.cpp | 2 +- graph/bitonicTSP.cpp | 4 ++-- graph/kruskal.cpp | 2 +- graph/maxWeightBipartiteMatching.cpp | 4 ++-- math/chineseRemainder.cpp | 3 +-- math/piLegendre.cpp | 2 +- string/suffixArray.cpp | 2 +- 10 files changed, 24 insertions(+), 25 deletions(-) diff --git a/datastructures/segmentTree.cpp b/datastructures/segmentTree.cpp index 09ff694..eb59d00 100644 --- a/datastructures/segmentTree.cpp +++ b/datastructures/segmentTree.cpp @@ -7,7 +7,7 @@ ll combine(ll a, ll b) { void init(vector& values) { tree.assign(sz(values)*2, 0); - copy(values.begin(), values.end(), tree.begin() + sz(values)); + copy(all(values), tree.begin() + sz(values)); for (int i = sz(tree)/2 - 1; i > 0; --i) { tree[i] = combine(tree[2*i], tree[2*i+1]); }} diff --git a/geometry/closestPair.cpp b/geometry/closestPair.cpp index a7662b6..7462dc0 100644 --- a/geometry/closestPair.cpp +++ b/geometry/closestPair.cpp @@ -12,14 +12,14 @@ bool compX(pt a, pt b) { : real(a) < real(b); } -double shortestDist(vector& points) { // points.size() > 1 +double shortestDist(vector& pts) { // pts.size() > 1 set status(compY); - sort(points.begin(), points.end(), compX); + sort(all(pts), compX); double opt = 1.0/0.0, sqrtOpt = 1.0/0.0; - auto left = points.begin(), right = points.begin(); + auto left = pts.begin(), right = pts.begin(); status.insert(*right); right++; - while (right != points.end()) { + while (right != pts.end()) { if (left != right && abs(real(*left - *right)) >= sqrtOpt) { status.erase(*left); diff --git a/geometry/convexHull.cpp b/geometry/convexHull.cpp index e988977..9245acc 100644 --- a/geometry/convexHull.cpp +++ b/geometry/convexHull.cpp @@ -1,18 +1,18 @@ -vector convexHull(vector p){ - sort(p.begin(), p.end(), [](const pt& a, const pt& b){ +vector convexHull(vector pts){ + sort(all(pts), [](const pt& a, const pt& b){ return real(a) == real(b) ? imag(a) < imag(b) : real(a) < real(b); }); - p.erase(unique(p.begin(), p.end()), p.end()); + pts.erase(unique(all(pts)), pts.end()); int k = 0; - vector h(2 * sz(p)); - for (int i = 0; i < sz(p); i++) {// Untere Hülle. - while (k > 1 && cross(h[k-2], h[k-1], p[i]) <= 0) k--; - h[k++] = p[i]; + vector h(2 * sz(pts)); + for (int i = 0; i < sz(pts); i++) {// Untere Hülle. + while (k > 1 && cross(h[k-2], h[k-1], pts[i]) <= 0) k--; + h[k++] = pts[i]; } - for (int i = sz(p)-2, t = k; i >= 0; i--) {// Obere Hülle. - while (k > t && cross(h[k-2], h[k-1], p[i]) <= 0) k--; - h[k++] = p[i]; + for (int i = sz(pts)-2, t = k; i >= 0; i--) {// Obere Hülle. + while (k > t && cross(h[k-2], h[k-1], pts[i]) <= 0) k--; + h[k++] = pts[i]; } h.resize(k); return h; diff --git a/geometry/linesAndSegments.cpp b/geometry/linesAndSegments.cpp index 6c53cee..9ed39c4 100644 --- a/geometry/linesAndSegments.cpp +++ b/geometry/linesAndSegments.cpp @@ -84,7 +84,7 @@ double distBetweenSegments(pt a, pt b, pt c, pt d) { // sortiert alle Punkte pts auf einer Linie // entsprechend der richtung dir 2d und 3d void sortLine(pt dir, vector& pts) { - sort(pts.begin(), pts.end(), [&](pt a, pt b){ + sort(all(pts), [&](pt a, pt b){ return dot(dir, a) < dot(dir, b); }); } \ No newline at end of file diff --git a/graph/bitonicTSP.cpp b/graph/bitonicTSP.cpp index 767bc5b..3dea828 100644 --- a/graph/bitonicTSP.cpp +++ b/graph/bitonicTSP.cpp @@ -25,7 +25,7 @@ void bitonicTSP() { } } while(n = j + 1, j > 0); (lt.back() == 1 ? lt : ut).push_back(0); - reverse(lt.begin(), lt.end()); - lt.insert(lt.end(), ut.begin(), ut.end()); + reverse(all(lt)); + lt.insert(lt.end(), all(ut)); //return lt;// Enthält Knoten 0 zweimal. An erster und letzter Position. } \ No newline at end of file diff --git a/graph/kruskal.cpp b/graph/kruskal.cpp index af5a8ff..5b0e153 100644 --- a/graph/kruskal.cpp +++ b/graph/kruskal.cpp @@ -1,4 +1,4 @@ -sort(edges.begin(), edges.end()); +sort(all(edges)); vector mst; int cost = 0; for (edge& e : edges) { diff --git a/graph/maxWeightBipartiteMatching.cpp b/graph/maxWeightBipartiteMatching.cpp index ef99232..e7e186e 100644 --- a/graph/maxWeightBipartiteMatching.cpp +++ b/graph/maxWeightBipartiteMatching.cpp @@ -54,6 +54,6 @@ double match(int l, int r) { y = prec; }} // Wert des Matchings - return accumulate(lx.begin(), lx.end(), 0.0) + - accumulate(ly.begin(), ly.end(), 0.0); + return accumulate(all(lx), 0.0) + + accumulate(all(ly), 0.0); } diff --git a/math/chineseRemainder.cpp b/math/chineseRemainder.cpp index 2308836..86a10ae 100644 --- a/math/chineseRemainder.cpp +++ b/math/chineseRemainder.cpp @@ -26,8 +26,7 @@ struct ChineseRemainder { // Löst das System. ll solve() { - M = accumulate(mods.begin(), mods.end(), lll(1), - multiplies()); + M = accumulate(all(mods), lll(1), multiplies()); inv.resize(sz(lhs)); for (int i = 0; i < sz(lhs); i++) { lll x = (M / mods[i]) % mods[i]; diff --git a/math/piLegendre.cpp b/math/piLegendre.cpp index f45ee85..21b974b 100644 --- a/math/piLegendre.cpp +++ b/math/piLegendre.cpp @@ -16,7 +16,7 @@ ll phi(ll n, ll k) { ll pi(ll n) { if (n < N) { // implement this as O(1) lookup for speedup! - return distance(primes.begin(), upper_bound(primes.begin(), primes.end(), n)); + return distance(primes.begin(), upper_bound(all(primes), n)); } else { ll k = pi(sqrtl(n) + 1); return n - phi(n, k) + k; diff --git a/string/suffixArray.cpp b/string/suffixArray.cpp index 66b0ee9..2650d72 100644 --- a/string/suffixArray.cpp +++ b/string/suffixArray.cpp @@ -12,7 +12,7 @@ struct SuffixArray { for (int i = 0; i < n; i++) L[i] = {{P[step-1][i], i+count < n ? P[step-1][i+count] : -1}, i}; - sort(L.begin(), L.end()); + sort(all(L)); for (int i = 0; i < n; i++) { P[step][L[i].second] = i > 0 && L[i].first == L[i-1].first ? -- cgit v1.2.3