Skip to content

Instantly share code, notes, and snippets.

@nascarsayan
Last active March 19, 2022 05:28
Show Gist options
  • Save nascarsayan/b9eb9a2ab97e16731ec917c65045ba82 to your computer and use it in GitHub Desktop.
Save nascarsayan/b9eb9a2ab97e16731ec917c65045ba82 to your computer and use it in GitHub Desktop.
VSCode Snippets
{
"cpbasic": {
"prefix": "cpbasic",
"description": "",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"#pragma region header__",
"",
"#pragma region aliases___",
"#define ff first",
"#define ss second",
"using ll = long long;",
"using ld = long double;",
"const char nl = '\\n';",
"using vi = vector<int>;",
"using vll = vector<ll>;",
"using vvll = vector<vll>;",
"using pll = pair<ll, ll>;",
"using ppll = pair<pll, pll>;",
"#define mkp make_pair",
"template <typename T1 = ll, typename T2 = ll>",
"using umap = unordered_map<T1, T2>;",
"template <typename T1 = ll, typename T2 = ll>",
"using omap = map<T1, T2>;",
"template <typename T = ll>",
"using uset = unordered_set<T>;",
"template <typename T = ll>",
"using umset = unordered_multiset<T>;",
"#define all(x) std::begin(x), std::end(x)",
"#define ign cin.ignore(1000, '\\n')",
"#pragma endregion aliases___",
"",
"#pragma region fast_file_io___",
"const string getEnvVar(string const &key) {",
" char *val = getenv(key.c_str());",
" return val == NULL ? string(\"\") : string(val);",
"}",
"inline void header() {",
" const string cfiopath = getEnvVar(\"CP_IO_PATH\");",
" if (!cfiopath.empty()) {",
" // local dev",
" const string ipath = cfiopath + \"/input.log\";",
" const string opath = cfiopath + \"/output.log\";",
" freopen(ipath.c_str(), \"r\", stdin);",
" // freopen(opath.c_str(), \"w\", stdout);",
" }",
" ios::sync_with_stdio(false);",
" cin.tie(nullptr);",
"}",
"#pragma endregion fast_file_io___",
"",
"#pragma endregion header__",
"",
"void solve() {",
" //",
"}",
"",
"int main() {",
" header();",
" ll t;",
" cin >> t;",
" while (t--) solve();",
" return 0;",
"}",
""
]
},
"cpdebug": {
"prefix": "cpdebug",
"description": "",
"body": [
"#pragma region debugging___",
"template <typename... Args, template <typename...> typename T>",
"string to_string(T<Args...> const &);",
"string to_string(string const &s) { return '\"' + s + '\"'; }",
"string to_string(char const &c) { return to_string(string(1, c)); }",
"string to_string(char const *c) { return to_string(string(c)); }",
"string to_string(bool const &b) { return (b ? \"T\" : \"F\"); }",
"template <typename... Args>",
"string to_string(pair<Args...> const &p) {",
" return \"(\" + to_string(p.first) + \", \" + to_string(p.second) + \")\";",
"}",
"template <typename... Args, template <typename...> typename T>",
"string to_string(T<Args...> const &S) {",
" string s = \"{\";",
" for (auto const &e : S) s += \" \" + to_string(e);",
" s += \" }\";",
" return s;",
"}",
"template <typename Tail>",
"void debug_out(Tail t) {",
" cout << \"[ \" << to_string(t) << \" ]\" << endl;",
"}",
"template <typename Head, typename... Tail>",
"void debug_out(Head h, Tail... t) {",
" cout << \" \" << to_string(h) << \",\";",
" debug_out(t...);",
"}",
"#define pr(...) cout << \"[\" << (#__VA_ARGS__) << \"] : [\", debug_out(__VA_ARGS__)",
"template <typename T>",
"void dbr(T lb, T ub) {",
" cout << '{';",
" for (auto it = lb; it != ub; it++) cout << ' ' << to_string(*it);",
" cout << \" }\" << endl;",
"}",
"#pragma endregion debugging___",
""
]
},
"pbds": {
"prefix": "pbds",
"description": "",
"body": [
"#pragma region policy_based_data_structures___",
"#include <ext/pb_ds/assoc_container.hpp>",
"namespace pbds = __gnu_pbds;",
"template <typename key, typename val = pbds::null_type,",
" typename comp = less<key>>",
"using ostree = pbds::tree<key, val, comp, pbds::rb_tree_tag,",
" pbds::tree_order_statistics_node_update>;",
"#pragma endregion policy_based_data_structures___",
""
]
},
"ncr": {
"prefix": "ncr",
"description": "",
"body": [
"#pragma region combinatorics___",
"ll fact[maxn + 1];",
"void factmemo() {",
" fact[0] = fact[1] = 1;",
" ll i;",
" for (i = 2; i <= maxn; i++) {",
" fact[i] = fact[i - 1];",
" mul(fact[i], i);",
" }",
"}",
"",
"ll ncr(ll n, ll r) {",
" if (n < r) return 0;",
" ll ans = fact[n];",
" mul(ans, inv(fact[r]));",
" mul(ans, inv(fact[n - r]));",
" return ans;",
"}",
"#pragma endregion combinatorics___",
""
]
},
"cpmod": {
"prefix": "cpmod",
"description": "",
"body": [
"#pragma region modular_arithmetic___",
"#define maxn long(1e6)",
"ll prm = 1e9 + 7;",
"",
"inline void add(ll &a, ll b, ll dom = prm) {",
" a = (a + b) % dom;",
" a = (a + dom) % dom;",
"}",
"",
"inline void sub(ll &a, ll b, ll dom = prm) {",
" a = (a - b) % dom;",
" a = (a + dom) % dom;",
"}",
"",
"inline void mul(ll &a, ll b, ll dom = prm) { a = (a * b) % dom; }",
"",
"ll binexp(ll b, ll e, ll dom = prm) {",
" ll ans = 1;",
" while (e > 0) {",
" if (e % 2 == 1) {",
" mul(ans, b);",
" }",
" mul(b, b);",
" e >>= 1;",
" }",
" return ans;",
"}",
"",
"ll inv(ll x, ll dom = prm) { return binexp(x, dom - 2, dom); }",
"#pragma endregion modular_arithmetic___",
""
]
},
"cpcmp": {
"prefix": "cpcmp",
"description": "",
"body": [
"#pragma region comparators___",
"template <typename T, typename Comp = less<T>>",
"bool smin(T &mem, T const &v, Comp const &cmp = Comp()) {",
" return cmp(v, mem) ? mem = v, true : false;",
"}",
"template <typename T, typename Comp = less<T>>",
"bool smax(T &mem, T const &v, Comp const &cmp = Comp()) {",
" return cmp(mem, v) ? mem = v, true : false;",
"}",
"#pragma endregion comparators___",
""
]
},
"cprnd": {
"prefix": "cprnd",
"description": "",
"body": [
"#pragma region randomization___",
"mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());",
"#pragma endregion randomization___",
""
]
},
"cpaliases": {
"prefix": "cpaliases",
"description": "",
"body": [
"#pragma region aliases___",
"#define ff first",
"#define ss second",
"using ll = long long;",
"using ld = long double;",
"const char nl = '\\n';",
"using vi = vector<int>;",
"using vll = vector<ll>;",
"using vvll = vector<vll>;",
"using pll = pair<ll, ll>;",
"using ppll = pair<pll, pll>;",
"#define mkp make_pair",
"template <typename T1 = ll, typename T2 = ll>",
"using umap = unordered_map<T1, T2>;",
"template <typename T1 = ll, typename T2 = ll>",
"using omap = map<T1, T2>;",
"template <typename T = ll>",
"using uset = unordered_set<T>;",
"template <typename T = ll>",
"using umset = unordered_multiset<T>;",
"#define all(x) std::begin(x), std::end(x)",
"#define ign cin.ignore(1000, '\\n')",
"#pragma endregion aliases___",
""
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment