Hello guys! I have seen many c++ templates, and most of them are realy ugly. For the sake of speed they make code unreadable. However, using no template make you loose a bunch of time. Now I want to say what macros make template ugly:
1. Long templates
The reason for it is simple: you can't type it in a real contest. Writing long templates (over 30-50 lines) makes it too dificiult to type it in a contest. For me, using these templates is cheating. At that point you can add every possible algo to your template and call it a day. That's not the templates are for
2. Using macros instead of for loops
Currrently, many people use #define rep(i, a, b) or #define FOR and etc. Besides making code hard to debug, it doesn't decrease time siginificantly. I can understand using it occasionaly, but using rep(i, a, b) instead of clasicall for is diabolical for me.
3. Unnececary macros
Sometimes when i look others code i see for example #define MAX(a, b) a = max(a, b) or #define sum(a + b) (a + b) % MOD. If you really hate MODs (which is understanable) you may use Mint (an easy struct that can be written in contest). But these things happen very rarely.
There is much more to write, but the main things are those. Here is my template: ~~~~~ // #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std;
// #define int long long
#define all(x) x.begin(), x.end()
#define inf (int)3e18
#define ff first
#define ss second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAX = 3e5 + 5, MOD = 1e9 + 7;
void solve()
{
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
cin >> tt;
// int cnt = 1;
while (tt--)
{
// cout << "Case " << cnt++ << ":\n";
solve();
}
}
~~~~~ There is some bad things here like using #define inf instead of adding it to const int. What i like about it: 1. It is short 2. It doesn't change the code drasticaly Btw there is a good tip: if you are using 1 based indexing and what to use x.begin(), x.end() you can use 1 + all(x). This works because 1 + all(x) = 1 + x.begin(), x.end(). Btw this is my first real blog :)



