-
For Ordered Set, use :
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define fbo find_by_order #define ook order_of_key template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // used as ordered_set<int> S; // S.insert(123); // use 'less_equal<T>' to support duplicates // S.ook(x) : number of elements in S strictly less than 'x' // S.size() - S.ook(x) : number of elements in S >= x // *S.fbo(i) : i'th element in S (0 - based indexing)
-
For random number generator: (add these two lines on top, range is [a, b] )
std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)-
Priority Queue Initialisation :
template<class T> using pq = priority_queue<T>; template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
-
For accurate square root use : (
credits : errichto)long long x = sqrtl(a) + 2; while (x * x > a) x--;
-
Grid cell (i, j) is uniquely mapped to (i + j * n) OR (j + i * m). Print the values.
-
Never use
endl, unless in interactive problems. Always make a habit of using'\n'for new line. -
Rather than clearing globals before each test case, you can also do:
// GLOBAL DECLARATION WITHOUT SIZE vector<vector<int>> adj; vector<vector<int>> up; vector<int> tin, tout; vector<int> depth; // INSIDE MAIN ASSIGN SIZE: adj = vector<vector<int>> (n + 5); up = vector<vector<int>> (n + 5, vector<int>(24)); tin = vector<int> (n + 5); tout = vector<int> (n + 5); depth = vector<int> (n + 5);
-
ckmaxandckmin. It returns TRUE if assignment happens else FALSE.template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }