Skip to content

Instantly share code, notes, and snippets.

@nascarsayan
Created July 30, 2021 16:16
Show Gist options
  • Save nascarsayan/fa6049b14673b7a0df568696486096e8 to your computer and use it in GitHub Desktop.
Save nascarsayan/fa6049b14673b7a0df568696486096e8 to your computer and use it in GitHub Desktop.
VSCode Snippets
{
"CP Template": {
"prefix": "cpt",
"body": [
"#include <bits/stdc++.h>",
"using namespace std;",
"/*----------------------------------------------------------------------------*/",
"#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 pll = pair<ll, ll>;",
"using ppll = pair<pll, pll>;",
"#define mkp make_pair",
"#define all(x) std::begin(x), std::end(x)",
"#define ign cin.ignore(1000, '\\n')",
"mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());",
"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;",
"}",
"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;",
"}",
"const string getEnvVar(string const &key) {",
" char *val = getenv(key.c_str());",
" return val == NULL ? string(\"\") : string(val);",
"}",
"vector<string> splitString(const string &str, const string &delim = \" \") {",
" vector<string> tokens;",
" size_t prev = 0, pos = 0;",
" do {",
" pos = str.find(delim, prev);",
" if (pos == string::npos) pos = str.length();",
" string token = str.substr(prev, pos - prev);",
" if (!token.empty()) tokens.push_back(token);",
" prev = pos + delim.length();",
" } while (pos < str.length() && prev < str.length());",
" return tokens;",
"}",
"void header() {",
" const string cfiopath = getEnvVar(\"AZ_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);",
"}",
"/*----------------------------------------------------------------------------*/",
"void solve() {",
" ",
"}",
"",
"int main() {",
" header();",
" ll t;",
" cin >> t;",
" while (t--)",
" solve();",
"}",
""
],
"description": "CP Template"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment