From 31a38b06374246212a57d211e9d80a3c30d1c977 Mon Sep 17 00:00:00 2001 From: hedwig100 Date: Sun, 24 Dec 2023 13:45:02 +0900 Subject: [PATCH 1/2] [fix] formatter --- .clang-format | 4 +- data_structures/binary_indexed_tree.cpp | 12 +- data_structures/binary_indexed_tree2d.cpp | 6 +- data_structures/convex_hull_trick.cpp | 27 ++--- data_structures/lazy_segment_tree.cpp | 9 +- data_structures/segment_tree.cpp | 11 +- .../sliding_window_aggregation.cpp | 15 ++- data_structures/unionfind.cpp | 12 +- data_structures/wavelet_matrix.cpp | 25 ++-- data_structures/weighted_unionfind.cpp | 20 +--- dynamic_programming/edit_distance.cpp | 6 +- .../longest_increasing_sequence.cpp | 18 +-- graph/beruman_ford.cpp | 11 +- graph/bfs.cpp | 3 +- graph/constrained_maxflow.cpp | 6 +- graph/dijkstra.cpp | 7 +- graph/dinic.cpp | 7 +- graph/kruscal.cpp | 7 +- graph/lowest_common_ancestor.cpp | 4 +- graph/lowlink.cpp | 6 +- graph/prim.cpp | 12 +- graph/primal_dual.cpp | 6 +- graph/primal_dual2.cpp | 6 +- graph/rerooting.cpp | 7 +- graph/strongly_connected_components.cpp | 10 +- math/accum1d.cpp | 3 +- math/bell_number.cpp | 7 +- math/euclid.cpp | 20 ++-- math/fast_fourier_transform.cpp | 6 +- math/kitamasa.cpp | 7 +- math/line.cpp | 53 ++++++--- math/matrix.cpp | 51 +++----- math/mint.cpp | 35 ++++-- math/mod_comb.cpp | 10 +- math/number_theoretic_transform.cpp | 7 +- math/number_theory.cpp | 17 ++- math/osa_k.cpp | 13 +- math/partition_number.cpp | 7 +- math/point.cpp | 111 ++++++++++++------ math/polygon.cpp | 15 +-- math/prime.cpp | 20 +--- math/stirling_number2.cpp | 7 +- math/zeta.cpp | 18 +-- other_algorithm/compress.cpp | 15 +-- other_algorithm/grid_utils.cpp | 4 +- other_algorithm/index_generator.cpp | 3 +- other_algorithm/perm_search.cpp | 3 +- other_algorithm/two_pointers.cpp | 28 ++--- string/mp.cpp | 4 +- string/rolling_hash.cpp | 11 +- string/trie.cpp | 19 +-- template/algorithm.cpp | 30 ++--- template/gcj.cpp | 27 ++--- template/marathon.cpp | 27 ++--- template/test.cpp | 27 ++--- test/bell_number.test.cpp | 3 +- test/beruman_ford.test.cpp | 4 +- test/bfs.test.cpp | 4 +- test/convex_hull.test.cpp | 6 +- test/convex_hull_trick_monotone.test.cpp | 6 +- test/dijkstra.test.cpp | 3 +- test/dinic.test.cpp | 3 +- test/edit_distance.test.cpp | 4 +- test/ext_gcd.test.cpp | 3 +- test/factorization.test.cpp | 3 +- test/factorization2.test.cpp | 3 +- test/inversion_number.test.cpp | 3 +- test/isp.test.cpp | 3 +- test/kruscal.test.cpp | 3 +- test/longest_common_sequence.test.cpp | 4 +- test/longest_increasing_sequence.test.cpp | 4 +- test/mod_comb.test.cpp | 4 +- test/partition_number.test.cpp | 3 +- test/polygon_area.test.cpp | 3 +- test/polygon_diameter.test.cpp | 3 +- test/prim.test.cpp | 3 +- test/primal_dual.test.cpp | 4 +- test/primal_dual2.test.cpp | 4 +- test/proj.test.cpp | 3 +- test/reflection.test.cpp | 3 +- test/rmq.test.cpp | 4 +- test/rmq_raq.test.cpp | 3 +- test/rmq_ruq.test.cpp | 29 +++-- test/rsq_raq.test.cpp | 17 +-- test/rsq_ruq.test.cpp | 11 +- test/ss_distance.test.cpp | 3 +- test/ss_intersection1.test.cpp | 3 +- test/ss_intersection2.test.cpp | 3 +- test/stirling_number2.test.cpp | 3 +- test/swag.test.cpp | 13 +- test/topological_sort.unverified.cpp | 4 +- test/two_pointers.test.cpp | 17 ++- 92 files changed, 528 insertions(+), 533 deletions(-) diff --git a/.clang-format b/.clang-format index 5280718..64a2fa8 100644 --- a/.clang-format +++ b/.clang-format @@ -6,5 +6,5 @@ AlignTrailingComments: true AllowShortIfStatementsOnASingleLine: true AllowShortBlocksOnASingleLine: true PointerAlignment: Right -ColumnLimit: 0 -IndentWidth: 4 +ColumnLimit: 80 +IndentWidth: 4 \ No newline at end of file diff --git a/data_structures/binary_indexed_tree.cpp b/data_structures/binary_indexed_tree.cpp index 1080590..9ccb236 100644 --- a/data_structures/binary_indexed_tree.cpp +++ b/data_structures/binary_indexed_tree.cpp @@ -8,8 +8,7 @@ using namespace std; // 1. A[0] + A[1] + ... + A[k] を求める. // 2. A[k] += x と更新. // -template -struct BinaryIndexedTree { +template struct BinaryIndexedTree { int n, size; int power; vector data; @@ -57,14 +56,11 @@ struct BinaryIndexedTree { // Σ_{l <= i < r} A[i]を求める. // 制約: 0 <= l <= r <= N // 計算量: O(logN) - T sum(int l, int r) { - return sum(r - 1) - sum(l - 1); - } + T sum(int l, int r) { return sum(r - 1) - sum(l - 1); } // lower_bound - // Σ_{0 <= i <= k} >= x を満たす最小のインデックスkを返す. そのようなものが存在しなければnを返す. - // 制約: A[i] >= 0 - // 計算量: O(logN) + // Σ_{0 <= i <= k} >= x を満たす最小のインデックスkを返す. + // そのようなものが存在しなければnを返す. 制約: A[i] >= 0 計算量: O(logN) int lower_bound(T x) { int k = 0; for (int r = size; r > 0; r >>= 1) { diff --git a/data_structures/binary_indexed_tree2d.cpp b/data_structures/binary_indexed_tree2d.cpp index c933cdd..e6a97af 100644 --- a/data_structures/binary_indexed_tree2d.cpp +++ b/data_structures/binary_indexed_tree2d.cpp @@ -3,8 +3,7 @@ using namespace std; // BinaryIndexedTree2D -template -struct BinaryIndexedTree2D { +template struct BinaryIndexedTree2D { int h, w; vector> data; @@ -49,6 +48,7 @@ struct BinaryIndexedTree2D { // 制約: 0 <= h1 <= h2 <= h,0 <= w1 <= w2 <= w // 計算量: O(loghlogw) T sum(int h1, int h2, int w1, int w2) { - return _sum(h2 - 1, w2 - 1) - _sum(h2 - 1, w1 - 1) - _sum(h1 - 1, w2 - 1) + _sum(h1 - 1, w1 - 1); + return _sum(h2 - 1, w2 - 1) - _sum(h2 - 1, w1 - 1) - + _sum(h1 - 1, w2 - 1) + _sum(h1 - 1, w1 - 1); } }; \ No newline at end of file diff --git a/data_structures/convex_hull_trick.cpp b/data_structures/convex_hull_trick.cpp index bfadd66..b97d298 100644 --- a/data_structures/convex_hull_trick.cpp +++ b/data_structures/convex_hull_trick.cpp @@ -7,20 +7,18 @@ namespace _cht { // Line // 直線を管理する構造体 -template -struct Line { +template struct Line { T a, b; Line(T a = 0, T b = 0) : a(a), b(b) {} - T f(T x) { - return a * x + b; - } + T f(T x) { return a * x + b; } bool operator<(const Line &rhs) const { if (a == rhs.a) return (b < rhs.b); return (a < rhs.a); } // necessary - // l1 <= *this <= l2であり, l1,l2が直線集合にあるときに自分が必要かどうか判定する関数. + // l1 <= *this <= l2であり, + // l1,l2が直線集合にあるときに自分が必要かどうか判定する関数. bool neccesary(const Line &l1, const Line &l2) const { if (l1.a == a) return false; if (l2.a == a) return true; @@ -30,15 +28,12 @@ struct Line { // ConvexHullTrickMonotone // 追加する直線の傾きに単調性がある場合のConvexHullTrick -template -struct ConvexHullTrickMonotone { +template struct ConvexHullTrickMonotone { int n; T sgn = MIN ? T(1) : T(-1); deque> lines; - ConvexHullTrickMonotone() : n(0) { - lines.resize(0); - } + ConvexHullTrickMonotone() : n(0) { lines.resize(0); } // add_right // y = ax + bなる直線を追加する. @@ -76,7 +71,9 @@ struct ConvexHullTrickMonotone { return make_pair(sgn * lines[l].f(x), ab); } - friend ostream &operator<<(ostream &os, const ConvexHullTrickMonotone &cht) noexcept { + friend ostream & + operator<<(ostream &os, + const ConvexHullTrickMonotone &cht) noexcept { for (int i = 0; i < cht.n; i++) { os << "l(" << cht.lines[i].a << ',' << cht.lines[i].b << "),"; } @@ -99,8 +96,7 @@ struct ConvexHullTrickMonotone { } // lは不必要 - if (l.a == lines.back().a && l.b >= lines.back().b) - return; + if (l.a == lines.back().a && l.b >= lines.back().b) return; while (n > 1 && !lines.back().neccesary(lines[n - 2], l)) { lines.pop_back(); @@ -127,8 +123,7 @@ struct ConvexHullTrickMonotone { } // lは不必要 - if (l.a == lines.front().a && l.b >= lines.front().b) - return; + if (l.a == lines.front().a && l.b >= lines.front().b) return; while (n > 1 && !lines.front().neccesary(l, lines[1])) { lines.pop_front(); diff --git a/data_structures/lazy_segment_tree.cpp b/data_structures/lazy_segment_tree.cpp index 89cf378..feb3966 100644 --- a/data_structures/lazy_segment_tree.cpp +++ b/data_structures/lazy_segment_tree.cpp @@ -14,15 +14,15 @@ using namespace std; // このとき, 以下の操作が可能 // 1. A[l]*...*A[r-1]を求める // 2. A[i] = A[i]^a (l <= i < r)と更新する -template -struct LazySegmentTree { +template struct LazySegmentTree { using Fx = function; using Fop = function; using Fy = function; int n, size, log; vector data; - vector lazy; // lazy[i] = i自身とiの子孫にこれから伝播しなければならない値 + vector + lazy; // lazy[i] = i自身とiの子孫にこれから伝播しなければならない値 Fx op; Mon e; @@ -31,7 +31,8 @@ struct LazySegmentTree { Fop mapping; LazySegmentTree(int n, Fx op, Mon e, Fy composition, OpMon id, Fop mapping) - : n(n), op(op), e(e), composition(composition), id(id), mapping(mapping) { + : n(n), op(op), e(e), composition(composition), id(id), + mapping(mapping) { size = 1, log = 0; while (size < n) size <<= 1, log++; diff --git a/data_structures/segment_tree.cpp b/data_structures/segment_tree.cpp index 2a74e6e..590ec35 100644 --- a/data_structures/segment_tree.cpp +++ b/data_structures/segment_tree.cpp @@ -11,8 +11,7 @@ using namespace std; // 以下の二つの操作ができる. // 1. A[x]を更新する // 2. A[l]*...*A[r-1] を計算する -template -struct SegmentTree { +template struct SegmentTree { using Fx = function; int n; @@ -67,9 +66,7 @@ struct SegmentTree { // A[k]を返す. // 制約: 0 <= k < n // 計算量: O(1) - Mon get(int k) { - return tree[k + size]; - } + Mon get(int k) { return tree[k + size]; } // prod // A[l]*...*A[r-1] を計算する. l = rのときはeを返す. @@ -95,8 +92,8 @@ struct SegmentTree { } // max_right - // l < r <= nでf(A[l]*...*A[r-1]) = trueなる最大のr, そのようなrが存在しない場合はlを返す. - // 制約: 0 <= l <= n,f(e) = true + // l < r <= nでf(A[l]*...*A[r-1]) = trueなる最大のr, + // そのようなrが存在しない場合はlを返す. 制約: 0 <= l <= n,f(e) = true // 計算量: O(logn) int max_right(int l, function f) { if (l == n) return n; diff --git a/data_structures/sliding_window_aggregation.cpp b/data_structures/sliding_window_aggregation.cpp index 8d78d46..bb983b1 100644 --- a/data_structures/sliding_window_aggregation.cpp +++ b/data_structures/sliding_window_aggregation.cpp @@ -7,9 +7,9 @@ using namespace std; // // push(x): xを追加する // pop(): queueの要領で要素を取り除く(FIFO) -// fold(): 今入っている要素を早く入っていた方からa0,a1,...,anとしたときにa0*a1*...anを計算する. -template -struct SlidingWindowAggregation { +// fold(): +// 今入っている要素を早く入っていた方からa0,a1,...,anとしたときにa0*a1*...anを計算する. +template struct SlidingWindowAggregation { using Fx = function; vector left, left_cum, right, right_cum; @@ -48,7 +48,8 @@ struct SlidingWindowAggregation { left.push_back(right.back()), left_cum.push_back(right.back()); right.pop_back(), right_cum.pop_back(); for (int i = 1; i < sz - 1; i++) { - left.push_back(right.back()), left_cum.push_back(op(right.back(), left_cum.back())); + left.push_back(right.back()), + left_cum.push_back(op(right.back(), left_cum.back())); right.pop_back(), right_cum.pop_back(); } right.pop_back(), right_cum.pop_back(); @@ -68,7 +69,8 @@ struct SlidingWindowAggregation { return op(left_cum.back(), right_cum.back()); } - friend ostream &operator<<(ostream &os, const SlidingWindowAggregation &swag) { + friend ostream &operator<<(ostream &os, + const SlidingWindowAggregation &swag) { for (int i = (int)swag.left.size() - 1; i >= 0; i--) os << swag.left[i] << ' '; for (int i = 0; i < (int)swag.right.size(); i++) @@ -79,7 +81,8 @@ struct SlidingWindowAggregation { // example: // using SemiGrp = pair; -// SlidingWindowAggregation swag([](const SemiGrp &a, const SemiGrp &b) { +// SlidingWindowAggregation swag([](const SemiGrp &a, const SemiGrp &b) +// { // if (a.first < b.first) // return b; // else diff --git a/data_structures/unionfind.cpp b/data_structures/unionfind.cpp index 6eaa2b8..1bac08e 100644 --- a/data_structures/unionfind.cpp +++ b/data_structures/unionfind.cpp @@ -8,9 +8,7 @@ struct UnionFind { int n; vector parents; - UnionFind(int n) : n(n) { - parents.assign(n, -1); - } + UnionFind(int n) : n(n) { parents.assign(n, -1); } // find // xの親を返す. @@ -36,16 +34,12 @@ struct UnionFind { // same // xとyが同じグループにいるか判定 // 制約: 0 <= x,y < n - bool same(int x, int y) { - return find(x) == find(y); - } + bool same(int x, int y) { return find(x) == find(y); } // size // xと同じグループのメンバーの個数 // 制約: 0 <= x < n - int size(int x) { - return -parents[find(x)]; - } + int size(int x) { return -parents[find(x)]; } // root // 根を全て列挙する diff --git a/data_structures/wavelet_matrix.cpp b/data_structures/wavelet_matrix.cpp index dbf38b0..17fcefa 100644 --- a/data_structures/wavelet_matrix.cpp +++ b/data_structures/wavelet_matrix.cpp @@ -7,7 +7,8 @@ struct FullyIndexableDictionary { vector bit; vector block; - FullyIndexableDictionary(int bit_size = 0) : bit_size(bit_size), block_size((bit_size + 32 - 1) >> 5) { + FullyIndexableDictionary(int bit_size = 0) + : bit_size(bit_size), block_size((bit_size + 32 - 1) >> 5) { bit.resize(bit_size, 0); block.resize(block_size, 0); } @@ -15,9 +16,7 @@ struct FullyIndexableDictionary { // set(k) set the k-th bit // constraint: 0 <= k < bit_size // time complexity: O(1) - void set(int k) { - bit[k >> 5] |= 1U << (k & 31); - } + void set(int k) { bit[k >> 5] |= 1U << (k & 31); } void build() { block[0] = 0; @@ -29,23 +28,20 @@ struct FullyIndexableDictionary { // op[k] returns k-th bit // constraint: 0 <= k < bit_size // time complexity: O(1) - bool operator[](int k) { - return bool((bit[k >> 5] >> (k & 31)) & 1U); - } + bool operator[](int k) { return bool((bit[k >> 5] >> (k & 31)) & 1U); } // _rank(k) returns the number of 1 in [0,k) // constraint: 0 <= k <= bit_size // time complexity: O(1) int _rank(int k) { - return block[k >> 5] + __builtin_popcount(bit[k >> 5] & ((1U << (k & 31)) - 1)); + return block[k >> 5] + + __builtin_popcount(bit[k >> 5] & ((1U << (k & 31)) - 1)); } // rank(v,k) returns the number of v in [0,k) // constraint: 0 <= k <= bit_size,(v = 0 or v = 1) // time complexity: O(1) - int rank(bool v, int k) { - return (v ? _rank(k) : k - _rank(k)); - } + int rank(bool v, int k) { return (v ? _rank(k) : k - _rank(k)); } // select(v,k) returns the k-th position of v // constraint: k >= 0, (v = 0 or v = 1) @@ -63,13 +59,10 @@ struct FullyIndexableDictionary { return r - 1; } - int select(bool v, int i, int l) { - return select(v, i + rank(v, l)); - } + int select(bool v, int i, int l) { return select(v, i + rank(v, l)); } }; -template -struct WaveletMatrix { +template struct WaveletMatrix { int len; FullyIndexableDictionary mat[MAXLOG]; int zeros[MAXLOG], buff1[MAXLOG], buff2[MAXLOG]; diff --git a/data_structures/weighted_unionfind.cpp b/data_structures/weighted_unionfind.cpp index 361560c..d8bbdc0 100644 --- a/data_structures/weighted_unionfind.cpp +++ b/data_structures/weighted_unionfind.cpp @@ -5,8 +5,7 @@ using namespace std; // WeightedUnionFind // 通常のUnionFindに加えて, 同じグループにいるノードの親に対する重みも // 管理するデータ構造. -template -struct WeightedUnionFind { +template struct WeightedUnionFind { int n; vector parents; vector diff_weight; @@ -41,15 +40,12 @@ struct WeightedUnionFind { // xとyが同じグループにいる時, xに対するyの重みを返す. // xとyが同じグループにいない時, 返す値には意味がない. // 制約: 0 <= x,y < n, xとyは同じグループ - Abel diff(int x, int y) { - return weight(y) - weight(x); - } + Abel diff(int x, int y) { return weight(y) - weight(x); } // unite // weight(y) = weight(x) + wとなるようにxとyを併合する. - // もしすでにxとyが同じグループでweight(y) != weight(x) + wであればfalseを返す. - // そうでない場合はtrueを返す. - // 制約: 0 <= x,y < n + // もしすでにxとyが同じグループでweight(y) != weight(x) + + // wであればfalseを返す. そうでない場合はtrueを返す. 制約: 0 <= x,y < n bool unite(int x, int y, Abel w) { w += weight(x); w -= weight(y); @@ -77,14 +73,10 @@ struct WeightedUnionFind { // same // xとyが同じかどうか判定する // 制約: 0 <= x,y < n - bool same(int x, int y) { - return find(x) == find(y); - } + bool same(int x, int y) { return find(x) == find(y); } // size // xと同じグループのサイズを返す. // 制約: 0 <= x < n - int size(int x) { - return -parents[find(x)]; - } + int size(int x) { return -parents[find(x)]; } }; \ No newline at end of file diff --git a/dynamic_programming/edit_distance.cpp b/dynamic_programming/edit_distance.cpp index 4fd3813..b2803f3 100644 --- a/dynamic_programming/edit_distance.cpp +++ b/dynamic_programming/edit_distance.cpp @@ -5,7 +5,8 @@ using namespace std; #include "../template/const.hpp" // edit_distance -// 文字列s,文字列tの編集距離, すなわち以下の操作をしてsをtに等しくするために必要な操作回数の最小値 +// 文字列s,文字列tの編集距離, +// すなわち以下の操作をしてsをtに等しくするために必要な操作回数の最小値 // 1. sから文字を一つ取り除く // 2. sに文字を一つ挿入する // 3. sの文字を一つ変換する @@ -21,7 +22,8 @@ int edit_distance(string s, string t) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j]; - dp[i + 1][j + 1] = min({dp[i + 1][j + 1], dp[i][j + 1] + 1, dp[i + 1][j] + 1, dp[i][j] + 1}); + dp[i + 1][j + 1] = min({dp[i + 1][j + 1], dp[i][j + 1] + 1, + dp[i + 1][j] + 1, dp[i][j] + 1}); } } return dp[n][m]; diff --git a/dynamic_programming/longest_increasing_sequence.cpp b/dynamic_programming/longest_increasing_sequence.cpp index 05bed11..1d8760a 100644 --- a/dynamic_programming/longest_increasing_sequence.cpp +++ b/dynamic_programming/longest_increasing_sequence.cpp @@ -4,13 +4,16 @@ using namespace std; // LongestIncreasingSequece // Aの最長増加部分列を求める. すなわち -// 0 <= i1 < i2 < ... < ik < n, A[i1] < A[i2] < ... < A[ik]なるkの最大値を求める。 -template -struct LongestIncreasingSequence { +// 0 <= i1 < i2 < ... < ik < n, A[i1] < A[i2] < ... < +// A[ik]なるkの最大値を求める。 +template struct LongestIncreasingSequence { - // dp[i] = 長さi+1であるような増加部分列での最後の要素の最小値, ない場合はINF - // dp_ind[i] = 長さi+1であるような増加部分列での最後の要素の最小値のインデックス, ない場合は-1 - // prev[i] = A[i]を含む中で最長の増加部分列でのA[i]の前の要素がA[j]であるときj, 先頭のときは-1 + // dp[i] = 長さi+1であるような増加部分列での最後の要素の最小値, + // ない場合はINF dp_ind[i] = + // 長さi+1であるような増加部分列での最後の要素の最小値のインデックス, + // ない場合は-1 prev[i] = + // A[i]を含む中で最長の増加部分列でのA[i]の前の要素がA[j]であるときj, + // 先頭のときは-1 int n; vector A, dp; vector prev, dp_ind; @@ -40,7 +43,8 @@ struct LongestIncreasingSequence { vector restore_lis() { vector ans; int max_len = lower_bound(dp.begin(), dp.end(), INF) - dp.begin(); - for (int now_ind = dp_ind[max_len - 1]; now_ind >= 0; now_ind = prev[now_ind]) + for (int now_ind = dp_ind[max_len - 1]; now_ind >= 0; + now_ind = prev[now_ind]) ans.push_back(A[now_ind]); reverse(ans.begin(), ans.end()); return ans; diff --git a/graph/beruman_ford.cpp b/graph/beruman_ford.cpp index 6e7f591..c209b88 100644 --- a/graph/beruman_ford.cpp +++ b/graph/beruman_ford.cpp @@ -4,8 +4,7 @@ using namespace std; // beruman_ford // 負辺を含むグラフを受け取り, sからの最短経路を計算する. -template -struct BerumanFord { +template struct BerumanFord { struct edge { int a, b; T c; @@ -29,9 +28,7 @@ struct BerumanFord { // add_edge // aからbへ辺重みcの辺をはる - void add_edge(int a, int b, T c) { - edges.push_back(edge{a, b, c}); - } + void add_edge(int a, int b, T c) { edges.push_back(edge{a, b, c}); } // solve // sからの最短経路を求める. もしsから到達可能な負閉路が存在すれば @@ -61,9 +58,7 @@ struct BerumanFord { // find_negloop_from_s // sから到達可能な負閉路が存在すればtrue, そうでなければfalseを返すkaesu. // 制約: solve()を呼んでいること - bool find_negloop_from_s() { - return find_negative_from_s; - } + bool find_negloop_from_s() { return find_negative_from_s; } // negloop_from_s // sからvまでの経路に負閉路が存在するならa[v]=1,そうでないときA[v]=0であるような diff --git a/graph/bfs.cpp b/graph/bfs.cpp index 4ac932e..a44b872 100644 --- a/graph/bfs.cpp +++ b/graph/bfs.cpp @@ -4,8 +4,7 @@ using namespace std; // Bfs // nは頂点数, Gはグラフを隣接リスト形式で持ったもの -template -struct Bfs { +template struct Bfs { int n; vector> G; vector dist, prev_v; diff --git a/graph/constrained_maxflow.cpp b/graph/constrained_maxflow.cpp index 18d17fb..78a99eb 100644 --- a/graph/constrained_maxflow.cpp +++ b/graph/constrained_maxflow.cpp @@ -6,13 +6,13 @@ using namespace std; // ConstrainedMaxFlow // 最小流量制約付き最大流問題をとく. -template -struct ConstrainedMaxFlow { +template struct ConstrainedMaxFlow { int n, super_s, super_t; T max_flow_from_super_s; Dinic flow_solver; - ConstrainedMaxFlow(int n) : n(n), super_s(n), super_t(n + 1), max_flow_from_super_s(0) { + ConstrainedMaxFlow(int n) + : n(n), super_s(n), super_t(n + 1), max_flow_from_super_s(0) { flow_solver.resize(n + 2); } diff --git a/graph/dijkstra.cpp b/graph/dijkstra.cpp index cbce0e2..0a03169 100644 --- a/graph/dijkstra.cpp +++ b/graph/dijkstra.cpp @@ -4,8 +4,7 @@ using namespace std; // Dijkstra // dijkstra法で最短経路を求める. -template -struct Dijkstra { +template struct Dijkstra { using edge = pair; int n; @@ -21,9 +20,7 @@ struct Dijkstra { // add_edge // aからbへコストcの辺を張る // 制約: c >= 0 - void add_edge(int a, int b, T c) { - G[a].emplace_back(c, b); - } + void add_edge(int a, int b, T c) { G[a].emplace_back(c, b); } // solve // sからの最短経路を求める. diff --git a/graph/dinic.cpp b/graph/dinic.cpp index e8e67a9..eb3d127 100644 --- a/graph/dinic.cpp +++ b/graph/dinic.cpp @@ -4,8 +4,7 @@ using namespace std; // Dinic // 最大流を求める. -template -struct Dinic { +template struct Dinic { struct edge { int to, rev; T cap; @@ -24,8 +23,8 @@ struct Dinic { } // resize - // グラフの頂点数をnにする. グラフ構築後に呼んでも多分壊れないが, グラフの構築前に呼ぶべき - // 制約: n >= 0 + // グラフの頂点数をnにする. グラフ構築後に呼んでも多分壊れないが, + // グラフの構築前に呼ぶべき 制約: n >= 0 void resize(int n) { G.resize(n); level.resize(n); diff --git a/graph/kruscal.cpp b/graph/kruscal.cpp index 81b6396..a90ec2b 100644 --- a/graph/kruscal.cpp +++ b/graph/kruscal.cpp @@ -6,8 +6,7 @@ using namespace std; // Kruscal // Kruscal法で最小全域森を求める. -template -struct Kruscal { +template struct Kruscal { struct edge { int a, b; T cost; @@ -24,9 +23,7 @@ struct Kruscal { // add_edge // aからbへコストcの辺を張る - void add_edge(int a, int b, T c) { - edges.emplace_back(a, b, c, m++); - } + void add_edge(int a, int b, T c) { edges.emplace_back(a, b, c, m++); } // solve // 最小全域森を求めて, そのコストを返す. diff --git a/graph/lowest_common_ancestor.cpp b/graph/lowest_common_ancestor.cpp index e1d58d7..0f85f1f 100644 --- a/graph/lowest_common_ancestor.cpp +++ b/graph/lowest_common_ancestor.cpp @@ -58,7 +58,5 @@ struct LowestCommonAncestor { return parents[u][0]; } - int operator[](int k) { - return dist[k]; - } + int operator[](int k) { return dist[k]; } }; \ No newline at end of file diff --git a/graph/lowlink.cpp b/graph/lowlink.cpp index 15f5f89..ef73a4c 100644 --- a/graph/lowlink.cpp +++ b/graph/lowlink.cpp @@ -6,7 +6,7 @@ struct LowLink { int N; vector> G; vector low, ord, articulation; - vector> bridge; + vector> bridge; LowLink(int N, vector> &G) : N(N), G(G) { low.assign(N, -1); @@ -36,7 +36,5 @@ struct LowLink { if (isArticulation) articulation.push_back(v); } - void build() { - dfs(0, 0); - } + void build() { dfs(0, 0); } }; \ No newline at end of file diff --git a/graph/prim.cpp b/graph/prim.cpp index a94ea67..9405aee 100644 --- a/graph/prim.cpp +++ b/graph/prim.cpp @@ -4,8 +4,7 @@ using namespace std; // Prim // Prim法で最小全域木を求める. -template -struct Prim { +template struct Prim { struct edge { int to; T cost; @@ -13,18 +12,15 @@ struct Prim { edge(int to, T c, int id) : to(to), cost(c), id(id) {} }; - function compare = [](const edge &a, const edge &b) { - return a.cost > b.cost; - }; + function compare = + [](const edge &a, const edge &b) { return a.cost > b.cost; }; int n; int m = 0; vector used_id; vector> G; - Prim(int n) : n(n) { - G.resize(n); - } + Prim(int n) : n(n) { G.resize(n); } // add_edge // aとbの間にコストcの無向辺をはる diff --git a/graph/primal_dual.cpp b/graph/primal_dual.cpp index 079fa23..9b6c696 100644 --- a/graph/primal_dual.cpp +++ b/graph/primal_dual.cpp @@ -5,8 +5,7 @@ using namespace std; // PrimalDual // ポテンシャルを用いて最小費用流を求める. // 最初のグラフには負閉路が含まれてはいけない. -template -struct PrimalDual { +template struct PrimalDual { struct edge { int to; Cap cap; @@ -73,7 +72,8 @@ struct PrimalDual { if (dist[v] < d) continue; for (int i = 0; i < (int)G[v].size(); i++) { edge &e = G[v][i]; - if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) { + if (e.cap > 0 && + dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) { dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]; prevv[e.to] = v; preve[e.to] = i; diff --git a/graph/primal_dual2.cpp b/graph/primal_dual2.cpp index 402840b..f7ceb59 100644 --- a/graph/primal_dual2.cpp +++ b/graph/primal_dual2.cpp @@ -5,8 +5,7 @@ using namespace std; // PrimalDual2 // berumanford法を用いて最小費用流を求める. // 最初のグラフには負閉路が含まれてはいけない. -template -struct PrimalDual2 { +template struct PrimalDual2 { struct edge { int to; Cap cap; @@ -65,8 +64,7 @@ struct PrimalDual2 { Cost ret_cost = 0; Cap ret_flow = 0; while (ret_flow < f) { - if (!beruman(s, t)) - break; + if (!beruman(s, t)) break; Cap d = f - ret_flow; for (int v = t; v != s; v = prevv[v]) { d = min(d, G[prevv[v]][preve[v]].cap); diff --git a/graph/rerooting.cpp b/graph/rerooting.cpp index 9f9eb30..d1fb1f3 100644 --- a/graph/rerooting.cpp +++ b/graph/rerooting.cpp @@ -14,8 +14,7 @@ struct DP { }; DP unit = DP(); // unit -template -struct Rerooting { +template struct Rerooting { int N; vector parents; vector> G; @@ -58,7 +57,5 @@ struct Rerooting { bfs(G[v][i], d.addroot(), v); } } - T operator[](int k) { - return ans[k]; - } + T operator[](int k) { return ans[k]; } }; \ No newline at end of file diff --git a/graph/strongly_connected_components.cpp b/graph/strongly_connected_components.cpp index f25eff1..899c11b 100644 --- a/graph/strongly_connected_components.cpp +++ b/graph/strongly_connected_components.cpp @@ -39,7 +39,8 @@ struct StronglyConnectedComponents { std::vector group, order; std::vector> scc_group, sccG; - // StronglyConnectedComponents receives N as the number of vertex of graph G. + // StronglyConnectedComponents receives N as the number of vertex of graph + // G. StronglyConnectedComponents(int N) : N(N) { G.resize(N); rG.resize(N); @@ -69,8 +70,7 @@ struct StronglyConnectedComponents { } } - if (!build_scc) - return; + if (!build_scc) return; sccG.resize(N_scc); for (int i = 0; i < N_scc; i++) { @@ -107,7 +107,5 @@ struct StronglyConnectedComponents { // scc[i] returns a group which vertex i belongs to. // this function is valid after build () is called. - int operator[](int i) { - return group[i]; - } + int operator[](int i) { return group[i]; } }; \ No newline at end of file diff --git a/math/accum1d.cpp b/math/accum1d.cpp index 19720d9..d3f9ddb 100644 --- a/math/accum1d.cpp +++ b/math/accum1d.cpp @@ -6,8 +6,7 @@ using namespace std; // 1次元累積和を計算する構造体 // n: 配列の長さ // m: インデックスの mod m ごとの累積和を計算する. m = 1で通常の累積和 -template -struct Accum1D { +template struct Accum1D { int n, m; vector A, cum; diff --git a/math/bell_number.cpp b/math/bell_number.cpp index e658b90..8cba42c 100644 --- a/math/bell_number.cpp +++ b/math/bell_number.cpp @@ -9,8 +9,7 @@ using namespace std; * n個の区別できるものをk個の区別できない箱に0個以上に分割する方法が何通りあるか求める. * これをB(n,k)としてベル数という. */ -template -struct BellNumber { +template struct BellNumber { int n, k; vector> dp; @@ -41,7 +40,5 @@ struct BellNumber { * B(i,j) を返す. * 制約: 0 <= i <= n,0 <= j <= k */ - T operator()(int i, int j) { - return dp[i][j]; - } + T operator()(int i, int j) { return dp[i][j]; } }; \ No newline at end of file diff --git a/math/euclid.cpp b/math/euclid.cpp index b167dfb..72bdb75 100644 --- a/math/euclid.cpp +++ b/math/euclid.cpp @@ -6,26 +6,20 @@ using namespace std; // 非負整数a,bの最大公約数を求める. // 制約: a,b >= 0 // 計算量: O(logmax(a,b)) -template -T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } +template T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } // lcm // 非負整数a,bの最小公倍数を求める. // 制約: a,b >= 0 // 計算量: O(logmax(a,b)) -template -T lcm(T a, T b) { return a / gcd(a, b) * b; } +template T lcm(T a, T b) { return a / gcd(a, b) * b; } // ext_gcd -// 拡張Euclidの互除法で非負整数a,bに対してax + by = gcd(a,b)を満たす整数x,yを求める. -// 出力される値は xy != 0 ならば |x| <= b,|y| <= a を満たす. -// 制約: a,b >= 0 -// 計算量: O(logmax(a,b)) -template -pair ext_gcd(T a, T b) { - if (b == 0) { - return make_pair(1, 0); - } +// 拡張Euclidの互除法で非負整数a,bに対してax + by = +// gcd(a,b)を満たす整数x,yを求める. 出力される値は xy != 0 ならば |x| <= b,|y| +// <= a を満たす. 制約: a,b >= 0 計算量: O(logmax(a,b)) +template pair ext_gcd(T a, T b) { + if (b == 0) { return make_pair(1, 0); } auto [x, y] = ext_gcd(b, a % b); return make_pair(y, x - a / b * y); } \ No newline at end of file diff --git a/math/fast_fourier_transform.cpp b/math/fast_fourier_transform.cpp index 005d559..44748df 100644 --- a/math/fast_fourier_transform.cpp +++ b/math/fast_fourier_transform.cpp @@ -69,7 +69,8 @@ class FastFourierTransform { class FastFourierTransform { private: - inline static void fft(vector> &F, bool inverse, int bit_len) { + inline static void fft(vector> &F, bool inverse, + int bit_len) { int degree = F.size(); for (int i = 0; i < degree; i++) { int j = 0; @@ -78,7 +79,8 @@ class FastFourierTransform { if (i < j) swap(F[i], F[j]); } for (int b = 1; b < degree; b <<= 1) { - complex x = 1, zeta = polar(1.0, PI / b * (inverse ? 1 : -1)); + complex x = 1, + zeta = polar(1.0, PI / b * (inverse ? 1 : -1)); for (int j = 0; j < b; j++) { for (int k = 0; k < degree; k += (b << 1)) { complex s = F[j + k], t = F[j + k + b] * x; diff --git a/math/kitamasa.cpp b/math/kitamasa.cpp index 310a6b2..be00dbc 100644 --- a/math/kitamasa.cpp +++ b/math/kitamasa.cpp @@ -7,8 +7,7 @@ using namespace std; // 線形漸化式: A_n = D_0A_{n-k} + ... D_{k-1}A_{n-1} // が与えられたときに // A_nをO(k^2logn)で求める. -template -struct Kitamasa { +template struct Kitamasa { int k; vector init, coef; @@ -27,9 +26,7 @@ struct Kitamasa { int msb = get_msb(n); for (int i = msb - 1; i >= 0; i--) { ret = mul2(ret); - if ((n >> i) & 1) { - ret = add1(ret); - } + if ((n >> i) & 1) { ret = add1(ret); } } T ans = T(0); for (int i = 0; i < k; i++) diff --git a/math/line.cpp b/math/line.cpp index 972ac81..7b81e98 100644 --- a/math/line.cpp +++ b/math/line.cpp @@ -9,12 +9,10 @@ using namespace std; constexpr long double GEOMETRY_INFTY = 1e9; // 無限遠点 -template -constexpr Point INFTY(GEOMETRY_INFTY, GEOMETRY_INFTY); +template constexpr Point INFTY(GEOMETRY_INFTY, GEOMETRY_INFTY); // 直線 -template -struct Line { +template struct Line { Point begin, end; Line() = default; Line(const Point &begin, const Point &end) : begin(begin), end(end) {} @@ -24,26 +22,29 @@ struct Line { }; // 半直線 -template -using Ray = Line; +template using Ray = Line; // 線分 -template -using Segment = Line; +template using Segment = Line; // ll_intersection // 直線同士の交点を返す. template Point ll_intersection(const Line &l1, const Line &l2) { - if (sgn(cross(l1.vec(), l2.vec())) == 0) return INFTY; // parallel or partially matched - return l1.begin + l1.vec() * cross(l2.vec(), l2.begin - l1.begin) / cross(l2.vec(), l1.vec()); // Intersection + if (sgn(cross(l1.vec(), l2.vec())) == 0) + return INFTY; // parallel or partially matched + return l1.begin + l1.vec() * cross(l2.vec(), l2.begin - l1.begin) / + cross(l2.vec(), l1.vec()); // Intersection } // ss_intersection // 線分同士の交点を求める. (線分が交わるかどうか, 交点)を返す. template -pair> ss_intersection(const Segment &s1, const Segment &s2) { - bool is_intersect = (iSP(s2.begin, s1.begin, s1.end) * iSP(s2.end, s1.begin, s1.end) <= 0 && iSP(s1.begin, s2.begin, s2.end) * iSP(s1.end, s2.begin, s2.end) <= 0); +pair> ss_intersection(const Segment &s1, + const Segment &s2) { + bool is_intersect = + (iSP(s2.begin, s1.begin, s1.end) * iSP(s2.end, s1.begin, s1.end) <= 0 && + iSP(s1.begin, s2.begin, s2.end) * iSP(s1.end, s2.begin, s2.end) <= 0); return {is_intersect, ll_intersection(s1, s2)}; } @@ -62,18 +63,23 @@ pair> sr_intersection(const Segment &s, const Ray &r) { // ison // 点pが線分s上の点かどうかを判定する. template -constexpr inline bool ison(const Point &p, const Segment &s) { return iSP(p, s.begin, s.end) == 0; } +constexpr inline bool ison(const Point &p, const Segment &s) { + return iSP(p, s.begin, s.end) == 0; +} // pl_distance // 点pと直線lの距離を求める. template -long double pl_distance(const Point &p, const Line &l) { return abs((long double)cross(l.vec(), p - l.begin) / length(l.vec())); } +long double pl_distance(const Point &p, const Line &l) { + return abs((long double)cross(l.vec(), p - l.begin) / length(l.vec())); +} // ps_distance // 点pと線分sの距離を求める. template long double ps_distance(const Point &p, const Segment &s) { - if (sgn(dot(s.vec(), p - s.begin)) < 0 || sgn(dot(s.countervec(), p - s.end)) < 0) { + if (sgn(dot(s.vec(), p - s.begin)) < 0 || + sgn(dot(s.countervec(), p - s.end)) < 0) { return min(dist(p, s.begin), dist(p, s.end)); } return pl_distance(p, s); @@ -84,20 +90,29 @@ long double ps_distance(const Point &p, const Segment &s) { template long double ss_distance(const Segment &s1, const Segment &s2) { if (ss_intersection(s1, s2).first) return 0; - return min({ps_distance(s1.begin, s2), ps_distance(s1.end, s2), ps_distance(s2.begin, s1), ps_distance(s2.end, s1)}); + return min({ps_distance(s1.begin, s2), ps_distance(s1.end, s2), + ps_distance(s2.begin, s1), ps_distance(s2.end, s1)}); } // proj // ベクトルpを直線lに射影した点を返す. -Point proj(const Point &p, const Line &l) { return l.begin + normalize(l.vec()) * (dot(l.vec(), p - l.begin) / length(l.vec())); } +Point proj(const Point &p, + const Line &l) { + return l.begin + + normalize(l.vec()) * (dot(l.vec(), p - l.begin) / length(l.vec())); +} // reflection // ベクトルpを直線lに対して反転させた点を返す. -Point reflection(const Point &p, const Line &l) { return proj(p, l) * 2 - p; } +Point reflection(const Point &p, + const Line &l) { + return proj(p, l) * 2 - p; +} // vertical_bisector // 点p,qの垂直二等分線を求める. -Line vertical_bisector(const Point &p, const Point &q) { +Line vertical_bisector(const Point &p, + const Point &q) { Point mid = (p + q) / 2, vec = rot90(p - q); return Line(mid, mid + vec); } diff --git a/math/matrix.cpp b/math/matrix.cpp index 2ba0062..9cf63bd 100644 --- a/math/matrix.cpp +++ b/math/matrix.cpp @@ -4,11 +4,9 @@ using namespace std; #include "mint.cpp" -template -using Matrix = vector>; +template using Matrix = vector>; -template -Matrix mul(const Matrix &a, const Matrix &b) { +template Matrix mul(const Matrix &a, const Matrix &b) { assert(a[0].size() == b.size()); Matrix c(a.size(), vector(b[0].size())); for (int i = 0; i < (int)a.size(); i++) { @@ -21,8 +19,7 @@ Matrix mul(const Matrix &a, const Matrix &b) { return c; } -template -vector mul(const Matrix &a, const vector &b) { +template vector mul(const Matrix &a, const vector &b) { assert(a[0].size() == b.size()); vector ans(a.size(), 0); for (int i = 0; i < (int)a.size(); i++) { @@ -33,33 +30,28 @@ vector mul(const Matrix &a, const vector &b) { return ans; } -template -Matrix pow(Matrix a, U n) { +template Matrix pow(Matrix a, U n) { assert(a.size() == a[0].size()); int m = (int)a.size(); Matrix ans(m, vector(m, 0)); for (int i = 0; i < m; i++) ans[i][i] = 1; while (n > 0) { - if (n & 1) { - ans = mul(ans, a); - } + if (n & 1) { ans = mul(ans, a); } a = mul(a, a); n >>= 1; } return ans; } -template -int _find_pivot(const Matrix> &a, int i) { +template int _find_pivot(const Matrix> &a, int i) { for (int j = i; j < (int)a[i].size(); j++) { if (a[j][i].x != 0) return j; } return -1; } -template -int _find_pivot(const Matrix &a, int i) { +template int _find_pivot(const Matrix &a, int i) { int pivot = -1; T val = T(0); for (int j = i; j < (int)a[i].size(); j++) { @@ -72,9 +64,9 @@ int _find_pivot(const Matrix &a, int i) { } // lu_decomposition -// PA = LUなる分解をする. ただし, Pは置換行列, Lは対角成分が1の下三角行列, Uは上三角行列. -// 置換PとL,Uを詰めた行列を返す. Aが正則ではない場合, Uの対角成分に0が含まれる. -// 計算量: O(n^3) +// PA = LUなる分解をする. ただし, Pは置換行列, Lは対角成分が1の下三角行列, +// Uは上三角行列. 置換PとL,Uを詰めた行列を返す. Aが正則ではない場合, +// Uの対角成分に0が含まれる. 計算量: O(n^3) template pair, Matrix> lu_decomposition(Matrix a) { assert(a.size() == a[0].size()); @@ -108,10 +100,10 @@ pair, Matrix> lu_decomposition(Matrix a) { constexpr inline bool _is_zero(long double x) { return abs(x) < 1e-8; } constexpr inline bool _is_zero(double x) { return abs(x) < 1e-8; } -template -constexpr inline bool _is_zero(const ModInt &x) { return x.x == 0; } -template -constexpr inline bool _is_zero(T x) { return x == T(0); } +template constexpr inline bool _is_zero(const ModInt &x) { + return x.x == 0; +} +template constexpr inline bool _is_zero(T x) { return x == T(0); } // solve // PA = LUを用いてAx = bなる連立方程式をとく. @@ -147,8 +139,7 @@ vector solve(vector p, const Matrix &lu, vector b) { // Ax = bなる連立方程式をとく. // もし解が存在しなければ{}を返す. 解が少なくとも一つ存在すればその一つを返す. // 計算量: O(n^3) -template -vector solve(Matrix A, vector b) { +template vector solve(Matrix A, vector b) { assert(A.size() == A[0].size()); auto [p, lu] = lu_decomposition(A); return solve(p, lu, b); @@ -157,8 +148,7 @@ vector solve(Matrix A, vector b) { // _det // lu分解された行列の行列式を求める. // 計算量: O(n) -template -T _det(const Matrix &lu) { +template T _det(const Matrix &lu) { T ans = T(1); for (int i = 0; i < (int)lu.size(); i++) ans *= lu[i][i]; @@ -168,8 +158,7 @@ T _det(const Matrix &lu) { // det // 行列の行列式を求める. // 計算量: O(n^3) -template -T det(Matrix A) { +template T det(Matrix A) { auto [_, lu] = lu_decomposition(A); return _det(lu); } @@ -177,8 +166,7 @@ T det(Matrix A) { // _rank // lu分解された行列のランクを求める. // 計算量: O(n) -template -int _rank(const Matrix &lu) { +template int _rank(const Matrix &lu) { int ans = (int)lu.size(); for (int i = 0; i < (int)lu.size(); i++) if (_is_zero(lu[i][i])) ans--; @@ -188,8 +176,7 @@ int _rank(const Matrix &lu) { // rank // 行列のランクを求める. // 計算量: O(n^3) -template -int rank(Matrix A) { +template int rank(Matrix A) { auto [_, lu] = lu_decomposition(A); return _rank(lu); } \ No newline at end of file diff --git a/math/mint.cpp b/math/mint.cpp index c137d2d..2a4ff2f 100644 --- a/math/mint.cpp +++ b/math/mint.cpp @@ -2,8 +2,7 @@ #include using namespace std; -template -struct ModInt { +template struct ModInt { public: long long x; ModInt(long long x = 0) : x((x % MOD + MOD) % MOD) {} @@ -19,15 +18,29 @@ struct ModInt { (x *= a.x) %= MOD; return *this; } - constexpr ModInt &operator/=(const ModInt a) noexcept { return *this *= a.inverse(); } + constexpr ModInt &operator/=(const ModInt a) noexcept { + return *this *= a.inverse(); + } - constexpr ModInt operator+(const ModInt a) const noexcept { return ModInt(*this) += a.x; } - constexpr ModInt operator-(const ModInt a) const noexcept { return ModInt(*this) -= a.x; } - constexpr ModInt operator*(const ModInt a) const noexcept { return ModInt(*this) *= a.x; } - constexpr ModInt operator/(const ModInt a) const noexcept { return ModInt(*this) /= a.x; } + constexpr ModInt operator+(const ModInt a) const noexcept { + return ModInt(*this) += a.x; + } + constexpr ModInt operator-(const ModInt a) const noexcept { + return ModInt(*this) -= a.x; + } + constexpr ModInt operator*(const ModInt a) const noexcept { + return ModInt(*this) *= a.x; + } + constexpr ModInt operator/(const ModInt a) const noexcept { + return ModInt(*this) /= a.x; + } - friend constexpr std::ostream &operator<<(std::ostream &os, const ModInt a) noexcept { return os << a.x; } - friend constexpr std::istream &operator>>(std::istream &is, ModInt &a) noexcept { + friend constexpr std::ostream &operator<<(std::ostream &os, + const ModInt a) noexcept { + return os << a.x; + } + friend constexpr std::istream &operator>>(std::istream &is, + ModInt &a) noexcept { is >> a.x; a.x = (a.x % MOD + MOD) % MOD; return is; @@ -57,6 +70,8 @@ struct ModInt { }; template -inline ModInt operator*(const U &c, const ModInt &a) { return {c * a.x}; } +inline ModInt operator*(const U &c, const ModInt &a) { + return {c * a.x}; +} using mint = ModInt<998244353>; \ No newline at end of file diff --git a/math/mod_comb.cpp b/math/mod_comb.cpp index 86a9886..4eb7221 100644 --- a/math/mod_comb.cpp +++ b/math/mod_comb.cpp @@ -7,8 +7,7 @@ using namespace std; // Combination // mod MODで階乗を計算しておくことでcomb(n,k)などをO(1) // で計算する. MODはconstな素数 -template -struct Combination { +template struct Combination { using mint = ModInt; int n; vector fact, ifact, invs; @@ -57,8 +56,7 @@ struct Combination { // nck_nbig // nが大きい時にnCkを計算する // 計算量: O(k) -template -ModInt nck_nbig(long long n, int k) { +template ModInt nck_nbig(long long n, int k) { using mint = ModInt; mint ans = 1; for (int i = 0; i < k; ++i) @@ -74,9 +72,7 @@ ModInt nck_nbig(long long n, int k) { long long modpow(long long x, long long y, long long m) { long long ans = 1, tmp = x; while (y > 0) { - if (y & 1) { - ans = (ans * tmp) % m; - } + if (y & 1) { ans = (ans * tmp) % m; } y >>= 1; tmp = (tmp * tmp) % m; } diff --git a/math/number_theoretic_transform.cpp b/math/number_theoretic_transform.cpp index fa6f006..06a5031 100644 --- a/math/number_theoretic_transform.cpp +++ b/math/number_theoretic_transform.cpp @@ -13,8 +13,8 @@ struct NumberTheoreticTransform { public: NumberTheoreticTransform() {} - // ntt calculates y[i] = \sum_{j=0}^{n-1} x[j]r^{ij} where n is length of x and r is n-th root of 1 (mod n) - // n must be power of two (n = 2^m) + // ntt calculates y[i] = \sum_{j=0}^{n-1} x[j]r^{ij} where n is length of x + // and r is n-th root of 1 (mod n) n must be power of two (n = 2^m) void ntt(int m, mint nth_root, std::vector &x) { if (m == 0) return; int n = (int)x.size(); @@ -37,7 +37,8 @@ struct NumberTheoreticTransform { } } - // multiply calculates f*g, when f[i] is coefficients of x^i (0-indexed) and g[i] is coefficients of x^i (0-indexed) + // multiply calculates f*g, when f[i] is coefficients of x^i (0-indexed) and + // g[i] is coefficients of x^i (0-indexed) std::vector multiply(std::vector f, std::vector g) { int min_sz = (int)f.size() + (int)g.size() + 1; int m = 0; diff --git a/math/number_theory.cpp b/math/number_theory.cpp index c4b6645..5266bdd 100644 --- a/math/number_theory.cpp +++ b/math/number_theory.cpp @@ -7,8 +7,7 @@ using namespace std; // pow_mod // x^k mod mを計算する. // 計算量: O(logk) -template -T pow_mod(T x, long long k, int m) { +template T pow_mod(T x, long long k, int m) { T ret = T(1); while (k > 0) { if (k & 1) { @@ -26,8 +25,7 @@ T pow_mod(T x, long long k, int m) { // ax = 1 (mod m) なるx (0 <= x < m)が存在するならば // それを返し, 存在しなければ-1を返す. // 計算量: O(log|max(a,m)|) -template -T inv_mod(T a, T m) { +template T inv_mod(T a, T m) { auto [x, y] = ext_gcd(a, m); T g = a * x + m * y; if (g != 1) return -1; @@ -36,10 +34,11 @@ T inv_mod(T a, T m) { // linear_congruence // forall i,A_i x = B_i mod M_i <=> x = b mod m -// とかけるときに(b,m)の組を返す. ただし(0 <= b < m)をみたす. このように書けない時は(-1,-1)を返す. -// 計算量: O(nlogmax|M_i|),nは式の数 +// とかけるときに(b,m)の組を返す. ただし(0 <= b < m)をみたす. +// このように書けない時は(-1,-1)を返す. 計算量: O(nlogmax|M_i|),nは式の数 template -pair linear_congruence(const vector &A, const vector &B, const vector &M) { +pair linear_congruence(const vector &A, const vector &B, + const vector &M) { T x = 0, m = 1; for (int i = 0; i < (int)A.size(); i++) { T a = A[i] * m, b = B[i] - A[i] * x, d = gcd(M[i], a); @@ -53,8 +52,8 @@ pair linear_congruence(const vector &A, const vector &B, const vecto // garner // forall i, x = R_i mod M_i <=> x = b mod m -// とかけるときに(b,m)の組を返す. ただし(0 <= b < m)をみたす. このように書けない時は(-1,-1)を返す. -// 計算量: O(nlogmax|M_i|),nは式の数 +// とかけるときに(b,m)の組を返す. ただし(0 <= b < m)をみたす. +// このように書けない時は(-1,-1)を返す. 計算量: O(nlogmax|M_i|),nは式の数 template pair garner(const vector &R, const vector &M) { vector A(R.size(), 1); diff --git a/math/osa_k.cpp b/math/osa_k.cpp index 20ef0e9..b191ced 100644 --- a/math/osa_k.cpp +++ b/math/osa_k.cpp @@ -9,9 +9,7 @@ struct OsaK { int n; vector smallest_prime_factor; - OsaK(int n) : n(n) { - smallest_prime_factor.assign(n + 1, -1); - } + OsaK(int n) : n(n) { smallest_prime_factor.assign(n + 1, -1); } // build // spf配列を用意する. @@ -22,7 +20,8 @@ struct OsaK { if (smallest_prime_factor[i] < 0) { smallest_prime_factor[i] = i; for (long long p = i * i; p <= n; p += i) { - if (smallest_prime_factor[p] < 0) smallest_prime_factor[p] = i; + if (smallest_prime_factor[p] < 0) + smallest_prime_factor[p] = i; } } } @@ -35,8 +34,7 @@ struct OsaK { // 整数mを素因数分解する // 制約: 1 <= m <= n // 計算量: O(logm) - template - vector> factorize(T m) { + template vector> factorize(T m) { vector> ans; while (m > 1) { int p = smallest_prime_factor[m], e = 1; @@ -54,8 +52,7 @@ struct OsaK { // 整数mの約数の数を数える. // 制約: 1 <= m <= n // 計算量: O(logm) - template - long long count_factor(T m) { + template long long count_factor(T m) { auto ret = factorize(m); long long ans = 1; for (const auto &p : ret) { diff --git a/math/partition_number.cpp b/math/partition_number.cpp index fb8f382..927d6fb 100644 --- a/math/partition_number.cpp +++ b/math/partition_number.cpp @@ -5,8 +5,7 @@ using namespace std; // PartionNumber // n個の区別できないものをk個の区別できない箱に0個以上に分割する方法が何通りあるか求める. // これをP(n,k)とするとP(n,0) = 0 (n > 0) -template -struct PartitionNumber { +template struct PartitionNumber { int n, k; vector> dp; @@ -29,7 +28,5 @@ struct PartitionNumber { // P(i,j)を返す. // 制約: 0 <= i <= n,0 <= j <= k - T operator()(int i, int j) { - return dp[i][j]; - } + T operator()(int i, int j) { return dp[i][j]; } }; \ No newline at end of file diff --git a/math/point.cpp b/math/point.cpp index 51fd31c..543f0d3 100644 --- a/math/point.cpp +++ b/math/point.cpp @@ -6,13 +6,14 @@ constexpr long double GEOMETRY_EPS = 1e-8; // sgn // a > 0なら1, a = 0なら0,a < 0なら-1を返す. -constexpr inline int sgn(const long double a) { return (a < -GEOMETRY_EPS ? -1 : (a > GEOMETRY_EPS ? 1 : 0)); } +constexpr inline int sgn(const long double a) { + return (a < -GEOMETRY_EPS ? -1 : (a > GEOMETRY_EPS ? 1 : 0)); +} constexpr inline int sgn(const int a) { return (a < 0 ? -1 : (a > 0 ? 1 : 0)); } // 2次元座標クラス // T = int,long doubleなど -template -struct Point { +template struct Point { T x, y; constexpr inline Point(T x = 0, T y = 0) : x(x), y(y) {} @@ -31,96 +32,134 @@ struct Point { y -= q.y; return *this; } - template - constexpr inline Point &operator*=(U a) { + template constexpr inline Point &operator*=(U a) { x *= a; y *= a; return *this; } - template - constexpr inline Point &operator/=(U a) { + template constexpr inline Point &operator/=(U a) { x /= a; y /= a; return *this; } // +,-,*,/ - constexpr inline Point operator+(const Point &q) const { return Point(*this) += q; } - constexpr inline Point operator-(const Point &q) const { return Point(*this) -= q; } - template - constexpr inline Point operator*(const U &a) const { return Point(*this) *= a; } - template - constexpr inline Point operator/(const U &a) const { return Point(*this) /= a; } + constexpr inline Point operator+(const Point &q) const { + return Point(*this) += q; + } + constexpr inline Point operator-(const Point &q) const { + return Point(*this) -= q; + } + template constexpr inline Point operator*(const U &a) const { + return Point(*this) *= a; + } + template constexpr inline Point operator/(const U &a) const { + return Point(*this) /= a; + } // <,> の比較は辞書順の比較, つまりx,yの順に大きい方を確認する. - inline bool operator<(const Point &q) const { return (sgn(x - q.x) != 0 ? sgn(x - q.x) < 0 : sgn(y - q.y) < 0); } - inline bool operator>(const Point &q) const { return (sgn(x - q.x) != 0 ? sgn(x - q.x) > 0 : sgn(y - q.y) > 0); } - inline bool operator==(const Point &q) const { return (sgn(x - q.x) == 0 && sgn(y - q.y) == 0); } + inline bool operator<(const Point &q) const { + return (sgn(x - q.x) != 0 ? sgn(x - q.x) < 0 : sgn(y - q.y) < 0); + } + inline bool operator>(const Point &q) const { + return (sgn(x - q.x) != 0 ? sgn(x - q.x) > 0 : sgn(y - q.y) > 0); + } + inline bool operator==(const Point &q) const { + return (sgn(x - q.x) == 0 && sgn(y - q.y) == 0); + } - friend ostream &operator<<(ostream &os, const Point &p) { return os << p.x << ' ' << p.y; } - friend istream &operator>>(istream &is, Point &p) { return is >> p.x >> p.y; } + friend ostream &operator<<(ostream &os, const Point &p) { + return os << p.x << ' ' << p.y; + } + friend istream &operator>>(istream &is, Point &p) { + return is >> p.x >> p.y; + } }; // *,/ template -inline Point operator*(const U &s, const Point &p) { return {s * p.x, s * p.y}; } +inline Point operator*(const U &s, const Point &p) { + return {s * p.x, s * p.y}; +} template -inline Point operator/(const U &s, const Point &p) { return {p.x / s, p.y / s}; } +inline Point operator/(const U &s, const Point &p) { + return {p.x / s, p.y / s}; +} // dot // p,qの内積を計算する. template -constexpr inline T dot(const Point &p, const Point &q) { return p.x * q.x + p.y * q.y; } +constexpr inline T dot(const Point &p, const Point &q) { + return p.x * q.x + p.y * q.y; +} // cross // p,qの外積を計算する template -constexpr inline T cross(const Point &p, const Point &q) { return p.x * q.y - q.x * p.y; } +constexpr inline T cross(const Point &p, const Point &q) { + return p.x * q.y - q.x * p.y; +} // length2 // ベクトルpの長さ(原点からの距離)の2乗を求める. -template -constexpr inline T length2(const Point &p) { return dot(p, p); } +template constexpr inline T length2(const Point &p) { + return dot(p, p); +} // length // ベクトルpの長さ(原点からの距離)を求める. -template -inline long double length(const Point &p) { return sqrt((long double)length2(p)); } +template inline long double length(const Point &p) { + return sqrt((long double)length2(p)); +} // dist // 点pと点qの間の距離を求める. template -inline long double dist(const Point &p, const Point &q) { return length(p - q); } +inline long double dist(const Point &p, const Point &q) { + return length(p - q); +} // sgn_area // p,q,rがつくる三角形の符号付き面積 template -constexpr inline long double sgn_area(const Point &p, const Point &q, const Point &r) { return (long double)cross(q - p, r - p) / 2.0; } +constexpr inline long double sgn_area(const Point &p, const Point &q, + const Point &r) { + return (long double)cross(q - p, r - p) / 2.0; +} // area // p,q,rがつくる三角形の面積 template -constexpr inline long double area(const Point &p, const Point &q, const Point &r) { return abs(sgn_area(p, q, r)); } +constexpr inline long double area(const Point &p, const Point &q, + const Point &r) { + return abs(sgn_area(p, q, r)); +} // normalize // 点pを長さ1に正規化した点を返す. -template -inline Point normalize(const Point &p) { return (Point)p / length(p); } +template inline Point normalize(const Point &p) { + return (Point)p / length(p); +} // rotation // 点pを反時計回りにargだけ回転させた点を返す. (argはradで測る) template -inline Point rotation(const Point &p, double arg) { return Point(cos(arg) * p.x - sin(arg) * p.y, sin(arg) * p.x + cos(arg) * p.y); } +inline Point rotation(const Point &p, double arg) { + return Point(cos(arg) * p.x - sin(arg) * p.y, + sin(arg) * p.x + cos(arg) * p.y); +} // angle // 点pのx軸の正の方向から反時計回りに測った角度を[-pi,pi]で返す. -template -inline long double angle(const Point &p) { return atan2(p.y, p.x); } +template inline long double angle(const Point &p) { + return atan2(p.y, p.x); +} // rot90 // 点pを反時計回りに90度回転 -template -constexpr inline Point rot90(const Point &p) { return Point(-p.y, p.x); } +template constexpr inline Point rot90(const Point &p) { + return Point(-p.y, p.x); +} // iSP // 異なる3点a,b,cの位置関係を返す. diff --git a/math/polygon.cpp b/math/polygon.cpp index 99ce77f..0fefe8d 100644 --- a/math/polygon.cpp +++ b/math/polygon.cpp @@ -7,8 +7,7 @@ using namespace std; // convex_hull // 点集合pointsの凸包を求める. // 求めた凸包は最も左にあるもののうち最も下にあるものから順に反時計回りに並んでいる. -template -vector> convex_hull(vector> points) { +template vector> convex_hull(vector> points) { sort(points.begin(), points.end()); int n = (int)points.size(), k = 0; vector> convex(2 * n); @@ -30,8 +29,7 @@ vector> convex_hull(vector> points) { // pointsのn点からなる多角形Gの面積を求める. // Gはpoints[i],points[(i + 1)%n]の2つの頂点を結ぶ線分を // 辺とする多角形である. -template -long double polygon_area(const vector> &points) { +template long double polygon_area(const vector> &points) { int n = (int)points.size(); long double ret = 0; for (int i = 0; i + 2 < n; i++) @@ -41,11 +39,9 @@ long double polygon_area(const vector> &points) { // diameter // 凸多角形convexの直径(最遠点対の距離)を求める. -template -long double diameter(const vector> &convex) { +template long double diameter(const vector> &convex) { int n = (int)convex.size(); - if (n == 2) - return dist(convex[0], convex[1]); + if (n == 2) return dist(convex[0], convex[1]); int i = 0, j = 0; for (int k = 0; k < n; k++) { @@ -57,7 +53,8 @@ long double diameter(const vector> &convex) { int si = i, sj = j; while (i != sj || j != si) { ret = max(ret, dist(convex[i], convex[j])); - if (sgn(cross(convex[(i + 1) % n] - convex[i], convex[(j + 1) % n] - convex[j])) < 0) + if (sgn(cross(convex[(i + 1) % n] - convex[i], + convex[(j + 1) % n] - convex[j])) < 0) i = (i + 1) % n; else j = (j + 1) % n; diff --git a/math/prime.cpp b/math/prime.cpp index 1b983ba..15c42bd 100644 --- a/math/prime.cpp +++ b/math/prime.cpp @@ -6,8 +6,7 @@ using namespace std; // 整数nが素数かどうか判定する. // 制約: n >= 1, // 計算量: O(√n) -template -bool is_prime(T n) { +template bool is_prime(T n) { for (T i = 2; i * i <= n; i++) { if (n % i == 0) return false; } @@ -18,8 +17,7 @@ bool is_prime(T n) { // 整数nの因数を列挙する. // 制約: n >= 1 // 計算量: O(√nlogn) -template -vector divisor(T n) { +template vector divisor(T n) { vector ans; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { @@ -35,8 +33,7 @@ vector divisor(T n) { // 整数nを素因数分解した結果を返す. // 制約: n >= 1 // 計算量: O(√n) -template -vector> prime_factor(T n) { +template vector> prime_factor(T n) { vector> ans; for (T i = 2; i * i <= n; i++) { int cnt = 0; @@ -60,9 +57,7 @@ struct Eratosthenes { vector is_primes, primes; public: - Eratosthenes(int n) : n(n) { - is_primes.assign(n + 1, 1); - } + Eratosthenes(int n) : n(n) { is_primes.assign(n + 1, 1); } // build // n以下の素数を全て返す @@ -82,16 +77,13 @@ struct Eratosthenes { // is_prime // 整数pが素数かどうか判定する // 制約: 1 <= p <= n - bool is_prime(int p) { - return is_primes[p]; - } + bool is_prime(int p) { return is_primes[p]; } // factorize // 整数mを素因数分解する // 制約: 1 <= m <= n*n // 計算量: O(min{n,√m}) - template - vector> factorize(T m) { + template vector> factorize(T m) { vector> ans; for (const int &p : primes) { if (p > m) break; diff --git a/math/stirling_number2.cpp b/math/stirling_number2.cpp index a0f0b28..acc8931 100644 --- a/math/stirling_number2.cpp +++ b/math/stirling_number2.cpp @@ -5,8 +5,7 @@ using namespace std; // StirlingNumber2 // n個の区別できるものをk個の区別できない箱に1個以上に分割する方法が何通りあるか求める. // これをS(n,k)とする. 第二種スターリング数 -template -struct StirlingNumber2 { +template struct StirlingNumber2 { int n, k; vector> dp; @@ -30,7 +29,5 @@ struct StirlingNumber2 { // S(i,j)を返す. // 制約: 0 <= i <= n, 0 <= j <= k - T operator()(int i, int j) { - return dp[i][j]; - } + T operator()(int i, int j) { return dp[i][j]; } }; \ No newline at end of file diff --git a/math/zeta.cpp b/math/zeta.cpp index b5a01ef..1a7e126 100644 --- a/math/zeta.cpp +++ b/math/zeta.cpp @@ -4,8 +4,7 @@ using namespace std; // a <= b <=> a <= b // g[x] = \\sum_{ i <= x } f[i] -template -struct ZetaOrder { +template struct ZetaOrder { // TODO:verify public: ZetaOrder() {} @@ -42,8 +41,7 @@ struct ZetaOrder { // min_pow2 returns minimum power of 2 larger than x (x <= 2^i) // and i (pair{i,2^i}). // x must be more than 0 -template -std::pair min_pow2(T x) { +template std::pair min_pow2(T x) { int i = 0; T ret = 1; while (x > ret) { @@ -55,8 +53,7 @@ std::pair min_pow2(T x) { // S <= T <=> S \subset T // g[T] = \sum_{ S \subset T } f[S] -template -struct ZetaSubset { +template struct ZetaSubset { // TODO:verify private: // min_pow2 returns minimum power of 2 larger than x (x <= 2^i) @@ -80,8 +77,7 @@ struct ZetaSubset { f.resize(sz, (R)0); for (int i = 0; i < d; i++) { for (int T = 0; T < sz; T++) { - if (T & (1 << i)) - f[T] += f[T ^ (1 << i)]; + if (T & (1 << i)) f[T] += f[T ^ (1 << i)]; } } } @@ -91,8 +87,7 @@ struct ZetaSubset { f.resize(sz, (R)0); for (int i = 0; i < d; i++) { for (int T = 0; T < sz; T++) { - if (T & (1 << i)) - f[T] -= f[T ^ (1 << i)]; + if (T & (1 << i)) f[T] -= f[T ^ (1 << i)]; } } } @@ -114,8 +109,7 @@ struct ZetaSubset { // a <= b <=> b | a // g[x] = \sum_{ x | i } f[i] -template -struct ZetaDiv { +template struct ZetaDiv { // TODO: O(nloglogn) zeta transform private: // min_pow2 returns minimum power of 2 larger than x (x <= 2^i) diff --git a/other_algorithm/compress.cpp b/other_algorithm/compress.cpp index 86d62d0..a9a1fed 100644 --- a/other_algorithm/compress.cpp +++ b/other_algorithm/compress.cpp @@ -2,8 +2,7 @@ #include using namespace std; -template -struct Compress { +template struct Compress { private: int n; vector A; @@ -18,15 +17,9 @@ struct Compress { val_to_id[A[i]] = i; } - int operator()(T val) { - return val_to_id[val]; - } + int operator()(T val) { return val_to_id[val]; } - T operator[](int id) { - return A[id]; - } + T operator[](int id) { return A[id]; } - int size() { - return n; - } + int size() { return n; } }; diff --git a/other_algorithm/grid_utils.cpp b/other_algorithm/grid_utils.cpp index 4a6064b..0977669 100644 --- a/other_algorithm/grid_utils.cpp +++ b/other_algorithm/grid_utils.cpp @@ -4,4 +4,6 @@ using namespace std; const int dy[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dx[8] = {0, 1, 0, -1, -1, 1, -1, 1}; -bool IN(int y, int x, int H, int W) { return (0 <= y) && (y < H) && (0 <= x) && (x < W); } \ No newline at end of file +bool IN(int y, int x, int H, int W) { + return (0 <= y) && (y < H) && (0 <= x) && (x < W); +} \ No newline at end of file diff --git a/other_algorithm/index_generator.cpp b/other_algorithm/index_generator.cpp index 6fe6dcb..2bd9daa 100644 --- a/other_algorithm/index_generator.cpp +++ b/other_algorithm/index_generator.cpp @@ -4,8 +4,7 @@ using namespace std; // Gridの(i,j)なるインデックスを1次元のインデックスに直す -template -struct IndexGenerator { +template struct IndexGenerator { T H, W; IndexGenerator(T H, T W) : H(H), W(W) {} T N() { return H * W; } diff --git a/other_algorithm/perm_search.cpp b/other_algorithm/perm_search.cpp index 5552553..b841fc3 100644 --- a/other_algorithm/perm_search.cpp +++ b/other_algorithm/perm_search.cpp @@ -4,7 +4,8 @@ using namespace std; // PermSearch // 順列を全探索する. -// 0~n-1までの数字からなる順列を探索する. fはある順列をvectorで受け取って処理をする関数 +// 0~n-1までの数字からなる順列を探索する. +// fはある順列をvectorで受け取って処理をする関数 struct PermSearch { int n; vector A; diff --git a/other_algorithm/two_pointers.cpp b/other_algorithm/two_pointers.cpp index d182aa9..d3fa5bf 100644 --- a/other_algorithm/two_pointers.cpp +++ b/other_algorithm/two_pointers.cpp @@ -6,10 +6,10 @@ using namespace std; // 条件Pを満たす連続部分列[l,r)の数え上げ, もしくは最大の長さを計算する. // ただし条件Pは以下の条件を満たすようなものでなければならない. // 条件 -// - 連続部分列[l,r)が条件Pを満たすとき, [l,r)内の任意の連続部分列が条件Pを満たす. +// - 連続部分列[l,r)が条件Pを満たすとき, +// [l,r)内の任意の連続部分列が条件Pを満たす. // -template -struct TwoPointers { +template struct TwoPointers { using Fcond = function; using Fincl = function; using Fincr = function; @@ -22,8 +22,9 @@ struct TwoPointers { Data data = initial_state; // cond - // dataは連続部分列[l,r-1)に関する情報を持っており, [l,r)が条件Pを満たす場合はtrue,そうでない時はfalseを返す. - // 制約: 0 <= l < r <= n + // dataは連続部分列[l,r-1)に関する情報を持っており, + // [l,r)が条件Pを満たす場合はtrue,そうでない時はfalseを返す. 制約: 0 <= l < + // r <= n Fcond cond; // increase_l @@ -58,8 +59,7 @@ struct TwoPointers { } count += r - l; max_length = max(max_length, r - l); - if (r == l) - increase_r(data, r); + if (r == l) increase_r(data, r); } } }; @@ -69,10 +69,10 @@ struct TwoPointers { // 条件Qを満たす連続部分列[l,r)の数え上げ, もしくは最小の長さを計算する. // ただし条件Qは以下の条件を満たすようなものでなければならない. // 条件 -// - 連続部分列[l,r)が条件Qを満たすとき, [l,r)を含む任意の連続部分列が条件Qを満たす. +// - 連続部分列[l,r)が条件Qを満たすとき, +// [l,r)を含む任意の連続部分列が条件Qを満たす. // -template -struct TwoPointers2 { +template struct TwoPointers2 { using Fcond = function; using Fincl = function; using Fincr = function; @@ -85,8 +85,9 @@ struct TwoPointers2 { Data data = initial_state; // cond - // dataは連続部分列[l,r)に関する情報を持っており, [l,r)が条件Qを満たす場合はtrue,そうでない時はfalseを返す. - // 制約: 0 <= l < r <= n + // dataは連続部分列[l,r)に関する情報を持っており, + // [l,r)が条件Qを満たす場合はtrue,そうでない時はfalseを返す. 制約: 0 <= l < + // r <= n Fcond cond; // increase_l @@ -126,8 +127,7 @@ struct TwoPointers2 { if (r == n + 1) break; count += n - r + 1; min_length = min(min_length, r - l); - if (r == l) - increase_r(data, r); + if (r == l) increase_r(data, r); } } }; diff --git a/string/mp.cpp b/string/mp.cpp index b88d188..39c4a12 100644 --- a/string/mp.cpp +++ b/string/mp.cpp @@ -4,8 +4,8 @@ using namespace std; // MP // l=(文字列Sの長さ)としてi=1,...,l+1について -// A[i] = (S[0:i)の接尾辞と接頭辞であって一致するようなものの最大の長さ, ただしS[0:i)全体は自明に一致するので除く) -// なる配列を返す。A[0]は常に-1 +// A[i] = (S[0:i)の接尾辞と接頭辞であって一致するようなものの最大の長さ, +// ただしS[0:i)全体は自明に一致するので除く) なる配列を返す。A[0]は常に-1 // complexity: O(|S|) vector MP(string s) { int l = (int)s.size(); diff --git a/string/rolling_hash.cpp b/string/rolling_hash.cpp index 4c766b7..2071875 100644 --- a/string/rolling_hash.cpp +++ b/string/rolling_hash.cpp @@ -38,7 +38,9 @@ struct RollingHash { } u64 get() { return hash[N]; } u64 get(int k) { return hash[k]; } - u64 get(int l, int r) { return CalcMod(hash[r] + POSITIVIZER - mul(hash[l], power[r - l])); } + u64 get(int l, int r) { + return CalcMod(hash[r] + POSITIVIZER - mul(hash[l], power[r - l])); + } }; mt19937_64 mt; @@ -57,10 +59,9 @@ struct RollingHash { RollingHash(string &s) { N = s.size(); - power1.resize(N + 1); power2.resize(N + 1); hash1.resize(N + 1); hash2.resize(N + 1); - power1[0] = 1; power2[0] = 1; hash1[0] = 0; hash2[0] = 0; - for (int i = 0;i < N; ++i) { - power1[i + 1] = power1[i] * B1 % M1; + power1.resize(N + 1); power2.resize(N + 1); hash1.resize(N + 1); +hash2.resize(N + 1); power1[0] = 1; power2[0] = 1; hash1[0] = 0; +hash2[0] = 0; for (int i = 0;i < N; ++i) { power1[i + 1] = power1[i] * B1 % M1; power2[i + 1] = power2[i] * B2 % M2; hash1[i + 1] = (hash1[i] * B1 + s[i]) % M1; hash2[i + 1] = (hash2[i] * B2 + s[i]) % M2; diff --git a/string/trie.cpp b/string/trie.cpp index 5e0e371..61a40e2 100644 --- a/string/trie.cpp +++ b/string/trie.cpp @@ -2,20 +2,15 @@ #include using namespace std; -template -struct Trie { +template struct Trie { struct Node { vector child, accept; int c, common; - Node(int c) : c(c), common(0) { - child.assign(char_size, -1); - } + Node(int c) : c(c), common(0) { child.assign(char_size, -1); } }; vector tree; int root; - Trie() : root(0) { - tree.push_back(Node(root)); - } + Trie() : root(0) { tree.push_back(Node(root)); } void insert(const string &s, int id) { int node_id = 0; for (int i = 0; i < (int)s.size(); ++i) { @@ -32,9 +27,7 @@ struct Trie { tree[node_id].accept.push_back(id); } // insert s to Trie - void insert(const string &s) { - insert(s, tree[0].common); - } + void insert(const string &s) { insert(s, tree[0].common); } // return the number of s in Trie int search(const string &s, bool prefix = false) { int node_id = 0; @@ -47,9 +40,7 @@ struct Trie { return prefix ? 1 : (int)tree[node_id].accept.size(); } // if prefix of s in Trie - bool prefix(const string &s) { - return search(s, true) > 0; - } + bool prefix(const string &s) { return search(s, true) > 0; } }; // Trie<26,'a'> tr \ No newline at end of file diff --git a/template/algorithm.cpp b/template/algorithm.cpp index f38db9d..273c923 100644 --- a/template/algorithm.cpp +++ b/template/algorithm.cpp @@ -1,16 +1,17 @@ #include using namespace std; #ifdef LOCAL_ -void debug_out() { - cerr << "\033[0m" << endl; -} -template -void debug_out(Head H, Tail... T) { +void debug_out() { cerr << "\033[0m" << endl; } +template void debug_out(Head H, Tail... T) { cerr << ' ' << H << ','; debug_out(T...); } -#define debug(...) cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " << #__VA_ARGS__ << ":", debug_out(__VA_ARGS__) -#define dump(x) cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl +#define debug(...) \ + cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " \ + << #__VA_ARGS__ << ":", \ + debug_out(__VA_ARGS__) +#define dump(x) \ + cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) @@ -37,8 +38,7 @@ ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } -template -ostream &operator<<(ostream &os, const vector &v) { +template ostream &operator<<(ostream &os, const vector &v) { os << '['; for (auto &e : v) { os << e << ','; @@ -46,8 +46,7 @@ ostream &operator<<(ostream &os, const vector &v) { os << ']'; return os; } -template -ostream &operator<<(ostream &os, const set &st) { +template ostream &operator<<(ostream &os, const set &st) { os << '{'; for (auto itr = st.begin(); itr != st.end(); itr++) { os << *itr << ','; @@ -69,18 +68,15 @@ void yn(bool cond, string Yes = "Yes", string No = "No") { cout << (cond ? Yes : No) << '\n'; } -template -bool chmax(T &x, const T &y) { +template bool chmax(T &x, const T &y) { return (x < y) ? (x = y, true) : false; } -template -bool chmin(T &x, const T &y) { +template bool chmin(T &x, const T &y) { return (x > y) ? (x = y, true) : false; } -template -vector id_sort(const vector &A) { +template vector id_sort(const vector &A) { vector> B(A.size()); for (int i = 0; i < (int)A.size(); i++) { B[i] = make_pair(A[i], i); diff --git a/template/gcj.cpp b/template/gcj.cpp index a0900da..5bb39bb 100644 --- a/template/gcj.cpp +++ b/template/gcj.cpp @@ -1,16 +1,17 @@ #include using namespace std; #ifdef LOCAL_ -void debug_out() { - cerr << "\033[0m" << endl; -} -template -void debug_out(Head H, Tail... T) { +void debug_out() { cerr << "\033[0m" << endl; } +template void debug_out(Head H, Tail... T) { cerr << ' ' << H << ','; debug_out(T...); } -#define debug(...) cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " << #__VA_ARGS__ << ":", debug_out(__VA_ARGS__) -#define dump(x) cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl +#define debug(...) \ + cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " \ + << #__VA_ARGS__ << ":", \ + debug_out(__VA_ARGS__) +#define dump(x) \ + cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) @@ -37,8 +38,7 @@ ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } -template -ostream &operator<<(ostream &os, const vector &v) { +template ostream &operator<<(ostream &os, const vector &v) { os << '['; for (auto &e : v) { os << e << ','; @@ -46,8 +46,7 @@ ostream &operator<<(ostream &os, const vector &v) { os << ']'; return os; } -template -ostream &operator<<(ostream &os, const set &st) { +template ostream &operator<<(ostream &os, const set &st) { os << '{'; for (auto itr = st.begin(); itr != st.end(); itr++) { os << *itr << ','; @@ -69,13 +68,11 @@ void yn(bool cond, string Yes = "Yes", string No = "No") { cout << (cond ? Yes : No) << '\n'; } -template -bool chmax(T &x, const T &y) { +template bool chmax(T &x, const T &y) { return (x < y) ? (x = y, true) : false; } -template -bool chmin(T &x, const T &y) { +template bool chmin(T &x, const T &y) { return (x > y) ? (x = y, true) : false; } diff --git a/template/marathon.cpp b/template/marathon.cpp index 04605b0..90081cf 100644 --- a/template/marathon.cpp +++ b/template/marathon.cpp @@ -1,16 +1,17 @@ #include using namespace std; #ifdef LOCAL_ -void debug_out() { - cerr << "\033[0m" << endl; -} -template -void debug_out(Head H, Tail... T) { +void debug_out() { cerr << "\033[0m" << endl; } +template void debug_out(Head H, Tail... T) { cerr << ' ' << H << ','; debug_out(T...); } -#define debug(...) cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " << #__VA_ARGS__ << ":", debug_out(__VA_ARGS__) -#define dump(x) cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl +#define debug(...) \ + cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " \ + << #__VA_ARGS__ << ":", \ + debug_out(__VA_ARGS__) +#define dump(x) \ + cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) @@ -37,8 +38,7 @@ ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } -template -ostream &operator<<(ostream &os, const vector &v) { +template ostream &operator<<(ostream &os, const vector &v) { os << '['; for (auto &e : v) { os << e << ','; @@ -46,8 +46,7 @@ ostream &operator<<(ostream &os, const vector &v) { os << ']'; return os; } -template -ostream &operator<<(ostream &os, const set &st) { +template ostream &operator<<(ostream &os, const set &st) { os << '{'; for (auto itr = st.begin(); itr != st.end(); itr++) { os << *itr << ','; @@ -69,13 +68,11 @@ void yn(bool cond, string Yes = "Yes", string No = "No") { cout << (cond ? Yes : No) << '\n'; } -template -bool chmax(T &x, const T &y) { +template bool chmax(T &x, const T &y) { return (x < y) ? (x = y, true) : false; } -template -bool chmin(T &x, const T &y) { +template bool chmin(T &x, const T &y) { return (x > y) ? (x = y, true) : false; } diff --git a/template/test.cpp b/template/test.cpp index b06a9e4..761a52c 100644 --- a/template/test.cpp +++ b/template/test.cpp @@ -1,16 +1,17 @@ #include using namespace std; #ifdef LOCAL_ -void debug_out() { - cerr << "\033[0m" << endl; -} -template -void debug_out(Head H, Tail... T) { +void debug_out() { cerr << "\033[0m" << endl; } +template void debug_out(Head H, Tail... T) { cerr << ' ' << H << ','; debug_out(T...); } -#define debug(...) cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " << #__VA_ARGS__ << ":", debug_out(__VA_ARGS__) -#define dump(x) cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl +#define debug(...) \ + cerr << "\033[1;36m" << __func__ << ":L" << __LINE__ << " " \ + << #__VA_ARGS__ << ":", \ + debug_out(__VA_ARGS__) +#define dump(x) \ + cerr << __func__ << ":L" << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) @@ -37,8 +38,7 @@ ostream &operator<<(ostream &os, const pair &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } -template -ostream &operator<<(ostream &os, const vector &v) { +template ostream &operator<<(ostream &os, const vector &v) { os << '['; for (auto &e : v) { os << e << ','; @@ -46,8 +46,7 @@ ostream &operator<<(ostream &os, const vector &v) { os << ']'; return os; } -template -ostream &operator<<(ostream &os, const set &st) { +template ostream &operator<<(ostream &os, const set &st) { os << '{'; for (auto itr = st.begin(); itr != st.end(); itr++) { os << *itr << ','; @@ -69,13 +68,11 @@ void yn(bool cond, string Yes = "Yes", string No = "No") { cout << (cond ? Yes : No) << '\n'; } -template -bool chmax(T &x, const T &y) { +template bool chmax(T &x, const T &y) { return (x < y) ? (x = y, true) : false; } -template -bool chmin(T &x, const T &y) { +template bool chmin(T &x, const T &y) { return (x > y) ? (x = y, true) : false; } diff --git a/test/bell_number.test.cpp b/test/bell_number.test.cpp index 0b4f598..80ec77e 100644 --- a/test/bell_number.test.cpp +++ b/test/bell_number.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_G" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_G" #include "../math/bell_number.cpp" #include "../math/mint.cpp" diff --git a/test/beruman_ford.test.cpp b/test/beruman_ford.test.cpp index c4faa79..6eb10e6 100644 --- a/test/beruman_ford.test.cpp +++ b/test/beruman_ford.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B&lang=jp" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=GRL_1_B&lang=jp" #include "../graph/beruman_ford.cpp" #include "../template/const.hpp" diff --git a/test/bfs.test.cpp b/test/bfs.test.cpp index 82efba7..7bc4798 100644 --- a/test/bfs.test.cpp +++ b/test/bfs.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C&lang=ja" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=ALDS1_11_C&lang=ja" #include "../graph/bfs.cpp" int main() { diff --git a/test/convex_hull.test.cpp b/test/convex_hull.test.cpp index 41cd495..8597723 100644 --- a/test/convex_hull.test.cpp +++ b/test/convex_hull.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_A" #define ERROR 1e-9 #include "../math/line.cpp" #include "../math/polygon.cpp" @@ -24,7 +25,8 @@ int main() { P start = INFTY; int ind = -1; for (int i = 0; i < k; i++) { - if (convex[i].y < start.y || (convex[i].y == start.y && convex[i].x < start.x)) { + if (convex[i].y < start.y || + (convex[i].y == start.y && convex[i].x < start.x)) { start = convex[i]; ind = i; } diff --git a/test/convex_hull_trick_monotone.test.cpp b/test/convex_hull_trick_monotone.test.cpp index 45424a8..e5e91aa 100644 --- a/test/convex_hull_trick_monotone.test.cpp +++ b/test/convex_hull_trick_monotone.test.cpp @@ -25,13 +25,15 @@ int main() { cht.add_left(0, 0); dp[0] = 0; for (int i = 1; i <= n; i++) { - dp[i] = cht.query(i).first + (ll)i * (i - 1) / 2 * b - (i - 1) * a + D[i - 1]; + dp[i] = cht.query(i).first + (ll)i * (i - 1) / 2 * b - (i - 1) * a + + D[i - 1]; cht.add_left(-i * b, dp[i] + i * a + (ll)i * (i + 1) * b / 2); } ll ans = HINF; for (int i = 0; i <= n; i++) { - ans = min(ans, w + dp[i] - (ll)(n - i) * a + (ll)(n - i) * (n - i + 1) / 2 * b); + ans = min(ans, w + dp[i] - (ll)(n - i) * a + + (ll)(n - i) * (n - i + 1) / 2 * b); } cout << ans << '\n'; return 0; diff --git a/test/dijkstra.test.cpp b/test/dijkstra.test.cpp index 40d392a..cc1ea3a 100644 --- a/test/dijkstra.test.cpp +++ b/test/dijkstra.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A" #include "../graph/dijkstra.cpp" #include "../template/const.hpp" diff --git a/test/dinic.test.cpp b/test/dinic.test.cpp index 880e2d1..229ed56 100644 --- a/test/dinic.test.cpp +++ b/test/dinic.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_6_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_6_A" #include "../graph/dinic.cpp" int main() { diff --git a/test/edit_distance.test.cpp b/test/edit_distance.test.cpp index 06a33e7..e56cf1f 100644 --- a/test/edit_distance.test.cpp +++ b/test/edit_distance.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E&lang=ja" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=DPL_1_E&lang=ja" #include "../dynamic_programming/edit_distance.cpp" int main() { diff --git a/test/ext_gcd.test.cpp b/test/ext_gcd.test.cpp index 34c58c9..b70ffea 100644 --- a/test/ext_gcd.test.cpp +++ b/test/ext_gcd.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E" #include "../math/euclid.cpp" int main() { diff --git a/test/factorization.test.cpp b/test/factorization.test.cpp index db51268..ec10601 100644 --- a/test/factorization.test.cpp +++ b/test/factorization.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/all/NTL_1_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/all/NTL_1_A" #include "../math/prime.cpp" const int MAXN = 100000; diff --git a/test/factorization2.test.cpp b/test/factorization2.test.cpp index f6545d6..fd757e1 100644 --- a/test/factorization2.test.cpp +++ b/test/factorization2.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/all/NTL_1_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/all/NTL_1_A" #include "../math/prime.cpp" const int MAXN = 100000; diff --git a/test/inversion_number.test.cpp b/test/inversion_number.test.cpp index 3c63a8a..b21a8e1 100644 --- a/test/inversion_number.test.cpp +++ b/test/inversion_number.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_D" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_D" #include "../data_structures/binary_indexed_tree.cpp" #include "../other_algorithm/compress.cpp" diff --git a/test/isp.test.cpp b/test/isp.test.cpp index 79f2b5b..f4e6224 100644 --- a/test/isp.test.cpp +++ b/test/isp.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_C" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_C" #define ERROR 1e-9 #include "../math/point.cpp" diff --git a/test/kruscal.test.cpp b/test/kruscal.test.cpp index e573dd8..34eed88 100644 --- a/test/kruscal.test.cpp +++ b/test/kruscal.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/2/GRL_2_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/2/GRL_2_A" #include "../graph/kruscal.cpp" #include "../template/const.hpp" diff --git a/test/longest_common_sequence.test.cpp b/test/longest_common_sequence.test.cpp index 2c88e86..86705e8 100644 --- a/test/longest_common_sequence.test.cpp +++ b/test/longest_common_sequence.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=ALDS1_10_C&lang=jp" #include "../dynamic_programming/longest_common_sequence.cpp" int main() { diff --git a/test/longest_increasing_sequence.test.cpp b/test/longest_increasing_sequence.test.cpp index eedb949..68c4b90 100644 --- a/test/longest_increasing_sequence.test.cpp +++ b/test/longest_increasing_sequence.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=DPL_1_D&lang=jp" #include "../dynamic_programming/longest_increasing_sequence.cpp" #include "../template/const.hpp" diff --git a/test/mod_comb.test.cpp b/test/mod_comb.test.cpp index 6a3032e..abda795 100644 --- a/test/mod_comb.test.cpp +++ b/test/mod_comb.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_5_D&lang=ja" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=DPL_5_D&lang=ja" #include "../math/mod_comb.cpp" int main() { diff --git a/test/partition_number.test.cpp b/test/partition_number.test.cpp index 8c6ee0f..3766320 100644 --- a/test/partition_number.test.cpp +++ b/test/partition_number.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_J" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_J" #include "../math/mint.cpp" #include "../math/partition_number.cpp" diff --git a/test/polygon_area.test.cpp b/test/polygon_area.test.cpp index 19825ce..c45c255 100644 --- a/test/polygon_area.test.cpp +++ b/test/polygon_area.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/3/CGL_3_A" #include "../math/polygon.cpp" using P = Point; diff --git a/test/polygon_diameter.test.cpp b/test/polygon_diameter.test.cpp index b3acea2..98fe83c 100644 --- a/test/polygon_diameter.test.cpp +++ b/test/polygon_diameter.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_B" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/4/CGL_4_B" #define ERROR 1e-9 #include "../math/polygon.cpp" diff --git a/test/prim.test.cpp b/test/prim.test.cpp index 334e753..2ce1c9e 100644 --- a/test/prim.test.cpp +++ b/test/prim.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/2/GRL_2_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/2/GRL_2_A" #include "../graph/prim.cpp" #include "../template/const.hpp" diff --git a/test/primal_dual.test.cpp b/test/primal_dual.test.cpp index 3ea2c2c..e22d781 100644 --- a/test/primal_dual.test.cpp +++ b/test/primal_dual.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_B&lang=ja" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=GRL_6_B&lang=ja" #include "../graph/primal_dual.cpp" #include "../template/const.hpp" diff --git a/test/primal_dual2.test.cpp b/test/primal_dual2.test.cpp index 3ee0048..53d168b 100644 --- a/test/primal_dual2.test.cpp +++ b/test/primal_dual2.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_B&lang=ja" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=GRL_6_B&lang=ja" #include "../graph/primal_dual2.cpp" #include "../template/const.hpp" diff --git a/test/proj.test.cpp b/test/proj.test.cpp index c8cc86e..54ee2cd 100644 --- a/test/proj.test.cpp +++ b/test/proj.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_A" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_A" #define ERROR 1e-9 #include "../math/line.cpp" diff --git a/test/reflection.test.cpp b/test/reflection.test.cpp index 8b725f4..d2fa000 100644 --- a/test/reflection.test.cpp +++ b/test/reflection.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_B" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_1_B" #define ERROR 1e-9 #include "../math/line.cpp" diff --git a/test/rmq.test.cpp b/test/rmq.test.cpp index 2923478..b386fd7 100644 --- a/test/rmq.test.cpp +++ b/test/rmq.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=DSL_2_A&lang=jp" #include "../data_structures/segment_tree.cpp" int main() { diff --git a/test/rmq_raq.test.cpp b/test/rmq_raq.test.cpp index ba7477c..06a2245 100644 --- a/test/rmq_raq.test.cpp +++ b/test/rmq_raq.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_H" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_H" #include "../data_structures/lazy_segment_tree.cpp" int main() { diff --git a/test/rmq_ruq.test.cpp b/test/rmq_ruq.test.cpp index 8555236..0588174 100644 --- a/test/rmq_ruq.test.cpp +++ b/test/rmq_ruq.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_F" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_F" #include "../data_structures/lazy_segment_tree.cpp" int main() { @@ -10,20 +11,18 @@ int main() { using Mon = long long; using OpMon = long long; - LazySegmentTree - lst( - n, - [](const Mon &x, const Mon &y) { return min(x, y); }, - (1LL << 31) - 1, - [](const OpMon &a, const OpMon &b) { - if (b < 0) return a; - return b; - }, - -1, - [](const Mon &x, const OpMon &a) { - if (a < 0) return x; - return a; - }); + LazySegmentTree lst( + n, [](const Mon &x, const Mon &y) { return min(x, y); }, + (1LL << 31) - 1, + [](const OpMon &a, const OpMon &b) { + if (b < 0) return a; + return b; + }, + -1, + [](const Mon &x, const OpMon &a) { + if (a < 0) return x; + return a; + }); int s, t, x, typ; for (int i = 0; i < q; i++) { diff --git a/test/rsq_raq.test.cpp b/test/rsq_raq.test.cpp index 5a155c0..abc99b0 100644 --- a/test/rsq_raq.test.cpp +++ b/test/rsq_raq.test.cpp @@ -12,14 +12,15 @@ int main() { long long val, length; }; using OpMon = long long; - LazySegmentTree - lst( - n, - [](const Mon &x, const Mon &y) { return Mon{x.val + y.val, x.length + y.length}; }, - {0, 0}, - [](const OpMon &a, const OpMon &b) { return a + b; }, - 0, - [](const Mon &x, const OpMon &a) { return Mon{x.val + x.length * a, x.length}; }); + LazySegmentTree lst( + n, + [](const Mon &x, const Mon &y) { + return Mon{x.val + y.val, x.length + y.length}; + }, + {0, 0}, [](const OpMon &a, const OpMon &b) { return a + b; }, 0, + [](const Mon &x, const OpMon &a) { + return Mon{x.val + x.length * a, x.length}; + }); vector A(n, Mon{0, 1}); lst.build(A); diff --git a/test/rsq_ruq.test.cpp b/test/rsq_ruq.test.cpp index 32f3bc2..c8b8dfa 100644 --- a/test/rsq_ruq.test.cpp +++ b/test/rsq_ruq.test.cpp @@ -14,11 +14,16 @@ int main() { using OpMon = int; const OpMon id = 1000000; - auto op = [](const Mon &x, const Mon &y) { return Mon{x.val + y.val, x.length + y.length}; }; + auto op = [](const Mon &x, const Mon &y) { + return Mon{x.val + y.val, x.length + y.length}; + }; auto composition = [&](const OpMon &a, const OpMon &b) { if (b == id) return a; - return b; }; - auto mapping = [&](const Mon &x, const OpMon &a) { return Mon{(a == id ? x.val : a * x.length), x.length}; }; + return b; + }; + auto mapping = [&](const Mon &x, const OpMon &a) { + return Mon{(a == id ? x.val : a * x.length), x.length}; + }; LazySegmentTree lst(n, op, {0, 0}, composition, id, mapping); vector A(n, {0, 1}); lst.build(A); diff --git a/test/ss_distance.test.cpp b/test/ss_distance.test.cpp index 0473ead..75f144e 100644 --- a/test/ss_distance.test.cpp +++ b/test/ss_distance.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/2/CGL_2_D" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/2/CGL_2_D" #define ERROR 1e-9 #include "../math/line.cpp" #include "../math/point.cpp" diff --git a/test/ss_intersection1.test.cpp b/test/ss_intersection1.test.cpp index 0aaa41d..5639390 100644 --- a/test/ss_intersection1.test.cpp +++ b/test/ss_intersection1.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_2_B" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_2_B" #define ERROR 1e-9 #include "../math/line.cpp" diff --git a/test/ss_intersection2.test.cpp b/test/ss_intersection2.test.cpp index 8ce93ef..1e32bcf 100644 --- a/test/ss_intersection2.test.cpp +++ b/test/ss_intersection2.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_2_C" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_2_C" #define ERROR 1e-9 #include "../math/line.cpp" diff --git a/test/stirling_number2.test.cpp b/test/stirling_number2.test.cpp index 8093524..cd5026f 100644 --- a/test/stirling_number2.test.cpp +++ b/test/stirling_number2.test.cpp @@ -1,7 +1,8 @@ #include using namespace std; -#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_I" +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_I" #include "../math/mint.cpp" #include "../math/stirling_number2.cpp" diff --git a/test/swag.test.cpp b/test/swag.test.cpp index 8f667d4..d0d213f 100644 --- a/test/swag.test.cpp +++ b/test/swag.test.cpp @@ -12,12 +12,13 @@ int main() { cin >> X[i]; using SemiGrp = pair; - SlidingWindowAggregation swag([](const SemiGrp &a, const SemiGrp &b) { - if (a.first < b.first) - return b; - else - return a; - }); + SlidingWindowAggregation swag( + [](const SemiGrp &a, const SemiGrp &b) { + if (a.first < b.first) + return b; + else + return a; + }); int max_diff = 0; int ai = -1, bi = -1; diff --git a/test/topological_sort.unverified.cpp b/test/topological_sort.unverified.cpp index af58c52..2e2c8f8 100644 --- a/test/topological_sort.unverified.cpp +++ b/test/topological_sort.unverified.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=ja" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=GRL_4_B&lang=ja" #include "../graph/topological_sort.cpp" int main() { diff --git a/test/two_pointers.test.cpp b/test/two_pointers.test.cpp index 8cac97b..fe59e9f 100644 --- a/test/two_pointers.test.cpp +++ b/test/two_pointers.test.cpp @@ -1,7 +1,9 @@ #include using namespace std; -#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_C&lang=jp" +#define PROBLEM \ + "https://judge.u-aizu.ac.jp/onlinejudge/" \ + "description.jsp?id=DSL_3_C&lang=jp" #include "../other_algorithm/two_pointers.cpp" int main() { @@ -13,10 +15,15 @@ int main() { long long x = 0; TwoPointers tp( - n, - [&](long long data, int r) { return data + A[r - 1] <= x; }, - [&](long long &data, int &l) { data -= A[l]; l++; }, - [&](long long &data, int &r) { data += A[r]; r++; }); + n, [&](long long data, int r) { return data + A[r - 1] <= x; }, + [&](long long &data, int &l) { + data -= A[l]; + l++; + }, + [&](long long &data, int &r) { + data += A[r]; + r++; + }); for (int i = 0; i < q; i++) { cin >> x; tp.solve(); From 9748514bcee7db9dab9903f3a9528a4189df1c89 Mon Sep 17 00:00:00 2001 From: GitHub Date: Sun, 24 Dec 2023 04:53:24 +0000 Subject: [PATCH 2/2] [auto-verifier] verify commit 31a38b06374246212a57d211e9d80a3c30d1c977 --- .verify-helper/timestamps.remote.json | 78 ++++++++++++--------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index 461d0d2..dc5d7a4 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -1,47 +1,37 @@ { -"test/bell_number.test.cpp": "2023-02-05 16:24:42 +0900", -"test/beruman_ford.test.cpp": "2022-10-23 13:46:28 +0900", -"test/bfs.test.cpp": "2022-08-28 17:14:39 +0900", -"test/binary_indexed_tree.test.cpp": "2022-09-05 23:20:29 +0900", -"test/convex_hull.test.cpp": "2022-09-19 14:09:28 +0900", -"test/convex_hull_trick_monotone.test.cpp": "2023-02-12 13:47:58 +0900", -"test/dijkstra.test.cpp": "2022-10-23 13:46:28 +0900", -"test/dinic.test.cpp": "2023-01-29 11:16:28 +0900", -"test/edit_distance.test.cpp": "2022-10-23 13:46:28 +0900", -"test/ext_gcd.test.cpp": "2022-08-30 16:11:35 +0900", -"test/factorization.test.cpp": "2022-12-03 23:34:11 +0900", -"test/factorization2.test.cpp": "2022-12-03 23:34:11 +0900", -"test/garner.test.cpp": "2022-09-22 13:17:16 +0900", -"test/gcd.test.cpp": "2022-12-03 23:34:11 +0900", -"test/gcd_convolutiion.test.cpp": "2023-01-28 20:23:48 +0900", -"test/inversion_number.test.cpp": "2022-09-05 23:20:29 +0900", -"test/isp.test.cpp": "2022-09-19 14:09:28 +0900", -"test/kruscal.test.cpp": "2022-10-23 13:46:28 +0900", -"test/longest_common_sequence.test.cpp": "2022-08-28 12:10:16 +0900", -"test/longest_increasing_sequence.test.cpp": "2022-10-23 13:46:28 +0900", -"test/mod_comb.test.cpp": "2023-01-28 20:23:48 +0900", -"test/ntt_recursive.test.cpp": "2023-01-28 20:23:48 +0900", -"test/partition_number.test.cpp": "2023-01-28 20:23:48 +0900", -"test/polygon_area.test.cpp": "2022-09-19 14:09:28 +0900", -"test/polygon_diameter.test.cpp": "2022-09-19 14:09:28 +0900", -"test/prim.test.cpp": "2022-10-23 13:46:28 +0900", -"test/primal_dual.test.cpp": "2022-10-23 13:46:28 +0900", -"test/primal_dual2.test.cpp": "2022-10-23 13:46:28 +0900", -"test/proj.test.cpp": "2022-09-19 14:09:28 +0900", -"test/reflection.test.cpp": "2022-09-19 14:09:28 +0900", -"test/rmq.test.cpp": "2022-09-04 14:36:51 +0900", -"test/rmq_raq.test.cpp": "2022-09-04 19:05:17 +0900", -"test/rmq_ruq.test.cpp": "2022-09-04 19:05:17 +0900", -"test/rsq_raq.test.cpp": "2022-09-04 20:28:19 +0900", -"test/rsq_ruq.test.cpp": "2022-09-04 20:28:19 +0900", +"test/bell_number.test.cpp": "2023-12-24 13:45:02 +0900", +"test/binary_indexed_tree.test.cpp": "2023-12-24 13:45:02 +0900", +"test/convex_hull.test.cpp": "2023-12-24 13:45:02 +0900", +"test/convex_hull_trick_monotone.test.cpp": "2023-12-24 13:45:02 +0900", +"test/dijkstra.test.cpp": "2023-12-24 13:45:02 +0900", +"test/dinic.test.cpp": "2023-12-24 13:45:02 +0900", +"test/ext_gcd.test.cpp": "2023-12-24 13:45:02 +0900", +"test/factorization.test.cpp": "2023-12-24 13:45:02 +0900", +"test/factorization2.test.cpp": "2023-12-24 13:45:02 +0900", +"test/garner.test.cpp": "2023-12-24 13:45:02 +0900", +"test/gcd.test.cpp": "2023-12-24 13:45:02 +0900", +"test/gcd_convolutiion.test.cpp": "2023-12-24 13:45:02 +0900", +"test/inversion_number.test.cpp": "2023-12-24 13:45:02 +0900", +"test/isp.test.cpp": "2023-12-24 13:45:02 +0900", +"test/kruscal.test.cpp": "2023-12-24 13:45:02 +0900", +"test/ntt_recursive.test.cpp": "2023-12-24 13:45:02 +0900", +"test/partition_number.test.cpp": "2023-12-24 13:45:02 +0900", +"test/polygon_area.test.cpp": "2023-12-24 13:45:02 +0900", +"test/polygon_diameter.test.cpp": "2023-12-24 13:45:02 +0900", +"test/prim.test.cpp": "2023-12-24 13:45:02 +0900", +"test/proj.test.cpp": "2023-12-24 13:45:02 +0900", +"test/reflection.test.cpp": "2023-12-24 13:45:02 +0900", +"test/rmq_raq.test.cpp": "2023-12-24 13:45:02 +0900", +"test/rmq_ruq.test.cpp": "2023-12-24 13:45:02 +0900", +"test/rsq_raq.test.cpp": "2023-12-24 13:45:02 +0900", +"test/rsq_ruq.test.cpp": "2023-12-24 13:45:02 +0900", "test/sample.test.cpp": "2022-06-26 19:41:05 +0900", -"test/ss_distance.test.cpp": "2022-09-19 14:09:28 +0900", -"test/ss_intersection1.test.cpp": "2022-09-19 14:09:28 +0900", -"test/ss_intersection2.test.cpp": "2022-09-19 14:09:28 +0900", -"test/stirling_number2.test.cpp": "2023-01-28 20:23:48 +0900", -"test/strongly_connected_components.test.cpp": "2022-08-27 12:40:11 +0900", -"test/swag.test.cpp": "2022-09-23 10:29:50 +0900", -"test/two_pointers.test.cpp": "2022-08-31 15:48:02 +0900", -"test/unionfind.test.cpp": "2022-08-28 18:43:40 +0900", -"test/weighted_unionfind.test.cpp": "2022-08-29 11:38:54 +0900" +"test/ss_distance.test.cpp": "2023-12-24 13:45:02 +0900", +"test/ss_intersection1.test.cpp": "2023-12-24 13:45:02 +0900", +"test/ss_intersection2.test.cpp": "2023-12-24 13:45:02 +0900", +"test/stirling_number2.test.cpp": "2023-12-24 13:45:02 +0900", +"test/strongly_connected_components.test.cpp": "2023-12-24 13:45:02 +0900", +"test/swag.test.cpp": "2023-12-24 13:45:02 +0900", +"test/unionfind.test.cpp": "2023-12-24 13:45:02 +0900", +"test/weighted_unionfind.test.cpp": "2023-12-24 13:45:02 +0900" } \ No newline at end of file