I have been preparing for competitive programming for a while now, and I have been looking at a lot of solutions that people have submitted to problems. One thing I have noticed is that most submissions which take low time to execute have weird looking boilerplate code at the start. This is a good example of what I am talking about.
If anyone feels too lazy to click on that link, then here you go:
#include #include #include using namespace std; template using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; #define ll long long int #define el "\n" #define sqr(x) ((x) * (x)) #define all(vec) (vec).begin(),(vec).end() template inline void ckmax(T &x, T y) {if (y > x) x = y; } template inline void ckmin(T &x, T y) {if (y < x) x = y; } #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator _it(_ss); err(_it, args); } void err(istream_iterator it) {} template void err(istream_iterator it, T a, Args... args) { cerr << *it << " =: " << a << endl; err(++it, args...); } template inline std::ostream& operator << (std::ostream& os, const std::pair& p) { return os << "(" << p.first << ": " << p.second << ")"; } template inline std::ostream &operator << (std::ostream & os,const std::vector& v) { bool first = true; os << "["; for(unsigned int i = 0; i < v.size(); i++) { if(!first) os << ", "; os << v[i]; first = false; } return os << "]"; } template inline std::ostream &operator << (std::ostream & os,const std::set& v) { bool first = true; os << "{"; for (typename std::set::const_iterator ii = v.begin(); ii != v.end(); ++ii) { if(!first) os << ", "; os << *ii; first = false; } return os << "}"; } template inline std::ostream &operator << (std::ostream & os,const std::map& v) { bool first = true; os << "{"; for (typename std::map::const_iterator ii = v.begin(); ii != v.end(); ++ii) { if(!first) os << ", "; os << *ii ; first = false; } return os << "}"; } template inline std::ostream &operator << (std::ostream & os,const std::unordered_set& v) { return os << std::set(v.begin(), v.end()); } template inline std::ostream &operator << (std::ostream & os,const ordered_set& v) { return os << std::set(v.begin(), v.end()); } template inline std::ostream &operator << (std::ostream & os,const std::unordered_map& v) { return os << std::map(v.begin(), v.end()); } const int MOD = 1e9 + 7; const long long INF = 1e18; const double EPS = 1e-6;
To me, it looks like a whole lot of mumbo-jumbo, probably because I am not too familiar with C++. Could anybody please explain, if not line-by-line, then at least on an overall how each statement or preprocessor directive benefits the execution of the program.