aboutsummaryrefslogtreecommitdiff
path: root/algo/debug.h
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-09-30 14:51:08 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-09-30 14:51:08 +0300
commit1e83036c3ff40310af6cf0d915ad1621d2eeeb83 (patch)
treec36d6a9f65cfdd7b631ea825111c684c1c22e6c2 /algo/debug.h
parent878180803f64f49062f5f7d9359ad711051f27d9 (diff)
downloadcompetitive-programming-1e83036c3ff40310af6cf0d915ad1621d2eeeb83.tar.xz
competitive-programming-1e83036c3ff40310af6cf0d915ad1621d2eeeb83.zip
Separated templates for debugging in a separate file
Diffstat (limited to 'algo/debug.h')
-rw-r--r--algo/debug.h123
1 files changed, 123 insertions, 0 deletions
diff --git a/algo/debug.h b/algo/debug.h
new file mode 100644
index 0000000..f7b1a0b
--- /dev/null
+++ b/algo/debug.h
@@ -0,0 +1,123 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+using ll = long long;
+using pii = pair<int, int>;
+using vpii = vector<pii>;
+using vi = vector<int>;
+using vll = vector<long long>;
+using mpii = map<int, int>;
+using mpll = map<ll, ll>;
+using db = long double;
+
+#define pb push_back
+#define all(x) (x).begin(), (x).end()
+#define rall(x) (x).rbegin(), (x).rend()
+#define lb lower_bound
+#define ub upper_bound
+#define make_unique(x) \
+ sort(all((x))); \
+ (x).resize(unique(all((x))) - (x).begin())
+#define ceil(a, b) ((a) + (b)-1) / (b)
+
+const int mod = (int)1e9 + 7;
+const db pi = acos((db)-1);
+const int dx[4]{1, 0, -1, 0};
+const int dy[4]{0, 1, 0, -1};
+
+template <typename k, typename v>
+ostream &operator<<(ostream &os, const pair<k, v> &p);
+template <typename t> ostream &operator<<(ostream &os, const vector<t> &vec);
+template <typename k, typename v>
+ostream &operator<<(ostream &os, const map<k, v> &m);
+template <typename k, typename v>
+ostream &operator<<(ostream &os, const unordered_map<k, v> &m);
+template <typename t> ostream &operator<<(ostream &os, const set<t> &s);
+template <typename t>
+ostream &operator<<(ostream &os, const unordered_set<t> &s);
+
+template <typename k, typename v>
+ostream &operator<<(ostream &os, const pair<k, v> &p) {
+ os << "(" << p.first << ", " << p.second << ")";
+ return os;
+}
+
+template <typename t> ostream &operator<<(ostream &os, const vector<t> &vec) {
+ os << "[";
+ for (size_t i = 0; i < vec.size(); ++i) {
+ if (i > 0)
+ os << ", ";
+ os << vec[i];
+ }
+ os << "]";
+ return os;
+}
+
+template <typename t>
+ostream &operator<<(ostream &os, const vector<vector<t>> &vec) {
+ os << "[\n";
+ for (size_t i = 0; i < vec.size(); ++i) {
+ os << " " << vec[i];
+ if (i > 0)
+ os << ", ";
+ os << '\n';
+ }
+ os << "]";
+ return os;
+}
+
+template <typename k, typename v>
+ostream &operator<<(ostream &os, const map<k, v> &m) {
+ os << "{";
+ for (const auto &p : m) {
+ os << p.first << ": " << p.second << ", ";
+ }
+ os << "}";
+ return os;
+}
+
+template <typename k, typename v>
+ostream &operator<<(ostream &os, const unordered_map<k, v> &m) {
+ os << "{";
+ for (const auto &p : m) {
+ os << p.first << ": " << p.second << ", ";
+ }
+ os << "}";
+ return os;
+}
+
+template <typename t> ostream &operator<<(ostream &os, const set<t> &s) {
+ int i = 0;
+ os << "{";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
+ os << e;
+ i++;
+ }
+ os << "}";
+ return os;
+}
+
+template <typename t>
+ostream &operator<<(ostream &os, const unordered_set<t> &s) {
+ int i = 0;
+ os << "{";
+ for (const auto &e : s) {
+ if (i > 0)
+ os << ", ";
+ os << e;
+ i++;
+ }
+ os << "}";
+ return os;
+}
+
+void debug_out() { cerr << endl; }
+
+template <typename head, typename... tail> void debug_out(head h, tail... t) {
+ cerr << h << '\n';
+ debug_out(t...);
+}
+
+#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):\n", debug_out(__VA_ARGS__)