Skip to content

Commit

Permalink
Update clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
knshnb committed Nov 20, 2019
1 parent 7d49a00 commit 24e032a
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 89 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
ColumnLimit: 120
AlwaysBreakTemplateDeclarations: false
---
3 changes: 1 addition & 2 deletions src/DataStructure/Accumulate2D.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
struct Accumulate2D {
template <class T> struct Accumulate2D {
vector<vector<T>> t; // 0-indexed!!
Accumulate2D(int n, int m) : t(n + 1, vector<T>(m + 1)) {}
T get(int i, int j) { return (i < 0 || j < 0) ? 0 : t[i][j]; }
Expand Down
3 changes: 1 addition & 2 deletions src/DataStructure/ConvexHullTrick.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <typename T, const T id = (int)-1e18>
class convex_hull_trick {
template <typename T, const T id = (int)-1e18> class convex_hull_trick {
struct line {
T a, b;
line(T a_ = 0, T b_ = 0) : a(a_), b(b_) {}
Expand Down
21 changes: 7 additions & 14 deletions src/DataStructure/LazySegmentTree.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// T0: 元の配列のモノイド
// T1: T0に対する作用素モノイド
template <class T0, class T1>
class BaseSegmentTree {
template <class T0, class T1> class BaseSegmentTree {
// k番目のノードにのlazyを伝搬
void eval(int k, int len) {
// 定数倍高速化
Expand Down Expand Up @@ -82,8 +81,7 @@ class BaseSegmentTree {
T0 query(int a) { return query(a, a + 1); }
};

template <class T0, class T1>
struct MinUpdateQuery : public BaseSegmentTree<T0, T1> {
template <class T0, class T1> struct MinUpdateQuery : public BaseSegmentTree<T0, T1> {
using BaseSegmentTree<T0, T1>::BaseSegmentTree;
static constexpr T0 _u0 = numeric_limits<T0>::max();
static constexpr T1 _u1 = numeric_limits<T1>::min();
Expand All @@ -94,8 +92,7 @@ struct MinUpdateQuery : public BaseSegmentTree<T0, T1> {
T1 p(T1 x, int len) override { return x; }
};

template <class T0, class T1>
struct SumAddQuery : public BaseSegmentTree<T0, T1> {
template <class T0, class T1> struct SumAddQuery : public BaseSegmentTree<T0, T1> {
using BaseSegmentTree<T0, T1>::BaseSegmentTree;
SumAddQuery() : SumAddQuery(0, 0) {}
T0 f0(T0 x, T0 y) override { return x + y; }
Expand All @@ -104,8 +101,7 @@ struct SumAddQuery : public BaseSegmentTree<T0, T1> {
T1 p(T1 x, int len) override { return x * len; }
};

template <class T0, class T1>
struct MinAddQuery : public BaseSegmentTree<T0, T1> {
template <class T0, class T1> struct MinAddQuery : public BaseSegmentTree<T0, T1> {
using BaseSegmentTree<T0, T1>::BaseSegmentTree;
static constexpr int _u0 = numeric_limits<T0>::max();
MinAddQuery() : MinAddQuery(_u0, 0) {}
Expand All @@ -115,8 +111,7 @@ struct MinAddQuery : public BaseSegmentTree<T0, T1> {
T1 p(T1 x, int len) override { return x; }
};

template <class T0, class T1>
struct SumUpdateQuery : public BaseSegmentTree<T0, T1> {
template <class T0, class T1> struct SumUpdateQuery : public BaseSegmentTree<T0, T1> {
using BaseSegmentTree<T0, T1>::BaseSegmentTree;
static constexpr int _u1 = numeric_limits<T1>::min();
SumUpdateQuery() : SumUpdateQuery(0, _u1) {}
Expand All @@ -126,8 +121,7 @@ struct SumUpdateQuery : public BaseSegmentTree<T0, T1> {
T1 p(T1 x, int len) override { return x == _u1 ? _u1 : x * len; }
};

template <class T0>
struct SumAffineQuery : public BaseSegmentTree<T0, pair<T0, T0>> {
template <class T0> struct SumAffineQuery : public BaseSegmentTree<T0, pair<T0, T0>> {
using T1 = pair<T0, T0>; // first * x + second
using BaseSegmentTree<T0, T1>::BaseSegmentTree;
static constexpr T1 _u1 = {1, 0};
Expand All @@ -142,8 +136,7 @@ struct SumAffineQuery : public BaseSegmentTree<T0, pair<T0, T0>> {
// update(i, j, {a, 0}); // 倍
};

template <class T>
struct MinmaxAffineQuery : public BaseSegmentTree<pair<T, T>, pair<T, T>> {
template <class T> struct MinmaxAffineQuery : public BaseSegmentTree<pair<T, T>, pair<T, T>> {
using T0 = pair<T, T>; // {min, max}
using T1 = pair<T, T>; // first * x + second
using BaseSegmentTree<T0, T1>::BaseSegmentTree;
Expand Down
8 changes: 2 additions & 6 deletions src/DataStructure/SegmentTree.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T, class F>
struct SegmentTree {
template <class T, class F> struct SegmentTree {
const F op;
const T e;
SegmentTree(F op_, T e_) : op(op_), e(e_) {}
Expand Down Expand Up @@ -38,10 +37,7 @@ struct SegmentTree {
while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
}
};
template <class T, class F>
auto make_segment_tree(F op, T e) {
return SegmentTree<T, F>(op, e);
}
template <class T, class F> auto make_segment_tree(F op, T e) { return SegmentTree<T, F>(op, e); }
// example
// auto seg_mi = make_segment_tree<Int>([](Int a, Int b) { return min(a, b); }, 1e18);
// auto seg_ma = make_segment_tree<Int>([](Int a, Int b) { return max(a, b); }, -1e18);
3 changes: 1 addition & 2 deletions src/DataStructure/SlideMin.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 自分を含んだK個前までの中での最小値のindexの配列を返す
// 最小(最大)値のindexを返すことに注意!
template <class T = int>
vector<int> slide_min(const vector<T>& a, int w, function<bool(T, T)> cmp = less<T>()) {
template <class T = int> vector<int> slide_min(const vector<T>& a, int w, function<bool(T, T)> cmp = less<T>()) {
int n = a.size();
vector<int> ret(n);
deque<int> dq;
Expand Down
3 changes: 1 addition & 2 deletions src/Graph/AbstractDijkstra.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
struct Graph {
template <class T> struct Graph {
struct Edge {
int to;
T cost;
Expand Down
6 changes: 2 additions & 4 deletions src/Graph/BellmanFord.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
template <class T>
struct Edge {
template <class T> struct Edge {
int from, to;
T cost;
};
// O(EV)、負のサイクルを通った後に到達できる点についてはdist[v]=INFを返す
template <class T>
vector<T> bellman_ford(vector<Edge<T>>& edges, int n, int s) {
template <class T> vector<T> bellman_ford(vector<Edge<T>>& edges, int n, int s) {
constexpr T INF = 1e18; // Tの型に応じて書き換える必要あり
vector<T> dist(n, INF);
dist[s] = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/Graph/Boruvka.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// F(現在の木の個数, vector<頂点->集合のindex>) -> vector<集合のindex->(cost, to)>
// 使い方: https://codeforces.com/contest/1242/submission/64467604
template <class T, class F>
T boruvka(int n, const F& f) {
template <class T, class F> T boruvka(int n, const F& f) {
struct UnionFind {
vector<int> number; // 0以上のとき親のindex, 負のときは集合サイズ
UnionFind(int n) : number(n, -1) {}
Expand Down
3 changes: 1 addition & 2 deletions src/Graph/WarshallFloyd.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
void warshall_floyd(vector<vector<T>> &d) {
template <class T> void warshall_floyd(vector<vector<T>> &d) {
int n = d.size();
for (int i = 0; i < n; i++) assert(d[i][i] == 0);
for (int k = 0; k < n; k++) {
Expand Down
3 changes: 1 addition & 2 deletions src/Math/DynamicModInt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
T pow(T x, int n, const T UNION = 1) {
template <class T> T pow(T x, int n, const T UNION = 1) {
T ret = UNION;
while (n) {
if (n & 1) ret *= x;
Expand Down
3 changes: 1 addition & 2 deletions src/Math/GaussJordan.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// A[n-1]にはAx = bのbの値
template <class T>
void gauss_jordan(vector<vector<T>>& A) {
template <class T> void gauss_jordan(vector<vector<T>>& A) {
int n = A.size(), m = A[0].size();
vector<bool> used(n);
for (int col = 0; col < m - 1; col++) {
Expand Down
3 changes: 1 addition & 2 deletions src/Math/Matrix.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
struct Matrix {
template <class T> struct Matrix {
vector<vector<T>> A;
Matrix() {}
Matrix(int n) : A(n, vector<T>(n, 0)) {}
Expand Down
11 changes: 4 additions & 7 deletions src/Math/ModInt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
T pow(T x, int n, const T UNION = 1) {
template <class T> T pow(T x, int n, const T UNION = 1) {
T ret = UNION;
while (n) {
if (n & 1) ret *= x;
Expand All @@ -9,8 +8,7 @@ T pow(T x, int n, const T UNION = 1) {
return ret;
}

template <int MD>
struct ModInt {
template <int MD> struct ModInt {
int x;
static unordered_map<int, int> to_inv;
ModInt() : x(0) {}
Expand Down Expand Up @@ -52,9 +50,8 @@ struct ModInt {
return s;
}
};
template <int MD>
unordered_map<int, int> ModInt<MD>::to_inv;
using mint = ModInt<MOD>;
template <int MD> unordered_map<int, int> ModInt<MD>::to_inv;
using mint = ModInt<1000000007>;

vector<mint> fact, fact_inv;
void init_factorial(int n) {
Expand Down
5 changes: 5 additions & 0 deletions src/Other/Directions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const vector<pair<int, int>> DIRECTIONS = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
4 changes: 4 additions & 0 deletions src/Other/GccTree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
4 changes: 4 additions & 0 deletions src/Other/MakeVec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
8 changes: 8 additions & 0 deletions src/Other/MsbLsb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int get_msb(long long x) {
assert(x != 0);
return 63 - __builtin_clzll(x);
}
int get_lsb(long long x) {
assert(x != 0);
return __builtin_ctzll(x);
}
1 change: 1 addition & 0 deletions src/Other/Random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
3 changes: 1 addition & 2 deletions src/String/LongestCommonPrefix.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T = int>
class SegTree {
template <class T = int> class SegTree {
using VT = vector<T>;
int orig_n;
// k番目のノードの[l, r)について[a, b)を求める
Expand Down
6 changes: 2 additions & 4 deletions src/String/Manacher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T>
vector<int> manacher(const vector<T>& s) {
template <class T> vector<int> manacher(const vector<T>& s) {
vector<int> R(s.size());
int i = 0, j = 0;
while (i < s.size()) {
Expand All @@ -15,8 +14,7 @@ vector<int> manacher(const vector<T>& s) {

struct Manacher {
vector<int> a;
template <class T>
Manacher(const vector<T>& s, T DUMMY = -1) {
template <class T> Manacher(const vector<T>& s, T DUMMY = -1) {
int m = s.size() * 2 - 1;
vector<T> t(m, DUMMY);
for (int i = 0; i < s.size(); i++) {
Expand Down
6 changes: 2 additions & 4 deletions src/String/RollingHash.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ull = unsigned long long;
template <class T>
struct RollingHash {
template <class T> struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const T &a, ull base, ull mod = 1000000009)
Expand Down Expand Up @@ -47,8 +46,7 @@ struct bases_t {
} bases;

using multihash_t = array<int, HASH_NUM>;
template <class T = vector<int>>
struct MultiRollingHash {
template <class T = vector<int>> struct MultiRollingHash {
vector<RollingHash<T>> rhs;
MultiRollingHash(const T &a) {
for (int i = 0; i < HASH_NUM; i++) {
Expand Down
3 changes: 1 addition & 2 deletions src/String/SuffixArrayDoubling.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <class T = int>
class SegTree {
template <class T = int> class SegTree {
using VT = vector<T>;
int orig_n;
// k番目のノードの[l, r)について[a, b)を求める
Expand Down
3 changes: 1 addition & 2 deletions src/String/Trie.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
template <char margin = 'A', int char_size = 26>
struct Trie {
template <char margin = 'A', int char_size = 26> struct Trie {
struct TrieNode {
array<int, char_size> node;
TrieNode() { node.fill(-1); };
Expand Down
64 changes: 38 additions & 26 deletions template.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using Int = long long;
#define REP(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
using ii = pair<Int, Int>;
template <class T> inline bool chmax(T& a, const T& b) {
if (a >= b) return false;
a = b;
return true;
}
template <class T> inline bool chmin(T& a, const T& b) {
if (a <= b) return false;
a = b;
return true;
}

template <class T> std::ostream& print(std::ostream& out, T const& val) { return (out << val << " "); }
template <class T1, class T2> std::ostream& print(std::ostream& out, std::pair<T1, T2> const& val) {
return (out << "{" << val.first << " " << val.second << "} ");
}
template <template <class, class...> class TT, class... Args>
std::ostream& operator<<(std::ostream& out, TT<Args...> const& cont) {
for (auto&& elem : cont) print(out, elem);
return out;
}

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
#define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " [" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), \
cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...);
}

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
struct SetupIO {
SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }
} setup_io;
// ******************************************************************************************************************
// **************************************** TEMPLATE END ************************************************************
// ******************************************************************************************************************

signed main() {
}
signed main() {}

0 comments on commit 24e032a

Please sign in to comment.