Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ AlignTrailingComments: true
AllowShortIfStatementsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
PointerAlignment: Right
ColumnLimit: 0
IndentWidth: 4
ColumnLimit: 80
IndentWidth: 4
78 changes: 34 additions & 44 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 4 additions & 8 deletions data_structures/binary_indexed_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ using namespace std;
// 1. A[0] + A[1] + ... + A[k] を求める.
// 2. A[k] += x と更新.
//
template <typename T>
struct BinaryIndexedTree {
template <typename T> struct BinaryIndexedTree {
int n, size;
int power;
vector<T> data;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions data_structures/binary_indexed_tree2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using namespace std;

// BinaryIndexedTree2D
template <typename T>
struct BinaryIndexedTree2D {
template <typename T> struct BinaryIndexedTree2D {
int h, w;
vector<vector<T>> data;

Expand Down Expand Up @@ -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);
}
};
27 changes: 11 additions & 16 deletions data_structures/convex_hull_trick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ namespace _cht {

// Line
// 直線を管理する構造体
template <typename T>
struct Line {
template <typename T> 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<T> &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<T> &l1, const Line<T> &l2) const {
if (l1.a == a) return false;
if (l2.a == a) return true;
Expand All @@ -30,15 +28,12 @@ struct Line {

// ConvexHullTrickMonotone
// 追加する直線の傾きに単調性がある場合のConvexHullTrick
template <typename T, bool MIN = true>
struct ConvexHullTrickMonotone {
template <typename T, bool MIN = true> struct ConvexHullTrickMonotone {
int n;
T sgn = MIN ? T(1) : T(-1);
deque<Line<T>> lines;

ConvexHullTrickMonotone() : n(0) {
lines.resize(0);
}
ConvexHullTrickMonotone() : n(0) { lines.resize(0); }

// add_right
// y = ax + bなる直線を追加する.
Expand Down Expand Up @@ -76,7 +71,9 @@ struct ConvexHullTrickMonotone {
return make_pair(sgn * lines[l].f(x), ab);
}

friend ostream &operator<<(ostream &os, const ConvexHullTrickMonotone<T, MIN> &cht) noexcept {
friend ostream &
operator<<(ostream &os,
const ConvexHullTrickMonotone<T, MIN> &cht) noexcept {
for (int i = 0; i < cht.n; i++) {
os << "l(" << cht.lines[i].a << ',' << cht.lines[i].b << "),";
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions data_structures/lazy_segment_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ using namespace std;
// このとき, 以下の操作が可能
// 1. A[l]*...*A[r-1]を求める
// 2. A[i] = A[i]^a (l <= i < r)と更新する
template <typename Mon, typename OpMon>
struct LazySegmentTree {
template <typename Mon, typename OpMon> struct LazySegmentTree {
using Fx = function<Mon(Mon, Mon)>;
using Fop = function<Mon(Mon, OpMon)>;
using Fy = function<OpMon(OpMon, OpMon)>;

int n, size, log;
vector<Mon> data;
vector<OpMon> lazy; // lazy[i] = i自身とiの子孫にこれから伝播しなければならない値
vector<OpMon>
lazy; // lazy[i] = i自身とiの子孫にこれから伝播しなければならない値

Fx op;
Mon e;
Expand All @@ -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++;
Expand Down
11 changes: 4 additions & 7 deletions data_structures/segment_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ using namespace std;
// 以下の二つの操作ができる.
// 1. A[x]を更新する
// 2. A[l]*...*A[r-1] を計算する
template <typename Mon>
struct SegmentTree {
template <typename Mon> struct SegmentTree {
using Fx = function<Mon(Mon, Mon)>;

int n;
Expand Down Expand Up @@ -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を返す.
Expand All @@ -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<bool(Mon)> f) {
if (l == n) return n;
Expand Down
15 changes: 9 additions & 6 deletions data_structures/sliding_window_aggregation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ using namespace std;
//
// push(x): xを追加する
// pop(): queueの要領で要素を取り除く(FIFO)
// fold(): 今入っている要素を早く入っていた方からa0,a1,...,anとしたときにa0*a1*...anを計算する.
template <typename SemiGrp>
struct SlidingWindowAggregation {
// fold():
// 今入っている要素を早く入っていた方からa0,a1,...,anとしたときにa0*a1*...anを計算する.
template <typename SemiGrp> struct SlidingWindowAggregation {
using Fx = function<SemiGrp(const SemiGrp &, const SemiGrp &)>;

vector<SemiGrp> left, left_cum, right, right_cum;
Expand Down Expand Up @@ -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();
Expand All @@ -68,7 +69,8 @@ struct SlidingWindowAggregation {
return op(left_cum.back(), right_cum.back());
}

friend ostream &operator<<(ostream &os, const SlidingWindowAggregation<SemiGrp> &swag) {
friend ostream &operator<<(ostream &os,
const SlidingWindowAggregation<SemiGrp> &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++)
Expand All @@ -79,7 +81,8 @@ struct SlidingWindowAggregation {

// example:
// using SemiGrp = pair<int, int>;
// SlidingWindowAggregation<SemiGrp> swag([](const SemiGrp &a, const SemiGrp &b) {
// SlidingWindowAggregation<SemiGrp> swag([](const SemiGrp &a, const SemiGrp &b)
// {
// if (a.first < b.first)
// return b;
// else
Expand Down
12 changes: 3 additions & 9 deletions data_structures/unionfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ struct UnionFind {
int n;
vector<int> parents;

UnionFind(int n) : n(n) {
parents.assign(n, -1);
}
UnionFind(int n) : n(n) { parents.assign(n, -1); }

// find
// xの親を返す.
Expand All @@ -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
// 根を全て列挙する
Expand Down
Loading