sidjha57

Siddharth CPP Template

Aug 12th, 2021 (edited)
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 5.79 KB | None | 0 0
  1.  
  2. {
  3.     "template": {
  4.         "prefix": "temp",
  5.         "body": [
  6.           "//Siddharth Jha",
  7.           "",
  8.           "#include<bits/stdc++.h>",
  9.           "//#include<ext/pb_ds/assoc_container.hpp>",
  10.           "//#include<ext/pb_ds/tree_policy.hpp>",
  11.           "//#include <ext/pb_ds/trie_policy.hpp>",
  12.           "//using namespace __gnu_pbds;",
  13.           "using namespace std;",
  14.           "//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;",
  15.           "//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;",
  16.           "",
  17.           "#define ll                       long long int",
  18.           "#define mod                      1000000007",
  19.           "#define inf                      1e18",
  20.           "#define pb                       push_back",
  21.           "#define vi                       vector<ll>",
  22.           "#define vs                       vector<string>",
  23.           "#define pii                      pair<ll,ll>",
  24.           "#define ump                      unordered_map",
  25.           "#define mp                       make_pair",
  26.           "#define pq_max                   priority_queue<ll>",
  27.           "#define pq_min                   priority_queue<ll,vi,greater<ll> >",
  28.           "#define all(n)                   n.begin(),n.end()",
  29.           "#define ff                       first",
  30.           "#define ss                       second",
  31.           "#define mid(l,r)                 (l+(r-l)/2)",
  32.           "#define bitc(n)                  __builtin_popcount(n)",
  33.           "#define SET(a)                   memset( a, -1, sizeof a )",
  34.           "#define CLR(a)                   memset( a,  0, sizeof a )",
  35.           "#define Pi                       3.141592653589793",
  36.           "#define loop(x,start,end)        for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))",
  37.           "#define _fast                    ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);",
  38.           "#define iter(container,it)       for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)",
  39.           "#define log(args...)             {string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }",
  40.           "#define logarr(arr,a,b)          for(int z=(a);z<=(b);z++) cout<<(arr[z])<<\" \";cout<<endl;",
  41.           "template <typename T> T          gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;}",
  42.           "template <typename T> T          lcm(T a, T b){return (a*(b/gcd(a,b)));}",
  43.           "vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}",
  44.           "",
  45.           "void err(istream_iterator<string> it) {}",
  46.           "template<typename T, typename... Args>",
  47.           "void err(istream_iterator<string> it, T a, Args... args) {",
  48.           "cout << *it << \" = \" << a << endl;",
  49.           "err(++it, args...);",
  50.           "}",
  51.           "",
  52.           "void solve() {",
  53.           "",
  54.           "}",
  55.           "",
  56.           "int main(int argc, char const *argv[]){",
  57.           "    _fast",
  58.           "  //#ifndef ONLINE_JUDGE",
  59.           "        //freopen(\"input.txt\", \"r\", stdin);",
  60.           "        //freopen(\"output.txt\", \"w\", stdout);",
  61.           "  //#endif",
  62.           "    ll t; cin>>t;",
  63.           "    while(t--){",
  64.           "     solve();",
  65.           "    }",
  66.           "  return 0;",
  67.           "}"
  68.         ],
  69.         "description": ""
  70.       },
  71.       "template 2": {
  72.         "prefix": "matrix",
  73.         "body": [
  74.           "const int MOD = 1e9 +7 ;",
  75.           "const long long MOD2 = static_cast <long long> (MOD)*MOD;",
  76.           "",
  77.           "struct Matrix {",
  78.           "  vector < vector <int> > mat;",
  79.           "  int n_rows,n_cols;",
  80.           "",
  81.           "  Matrix() {}",
  82.           "",
  83.           "  Matrix (vector < vector<int> > values) : mat(values), n_rows(values.size()),",
  84.           "          n_cols(values[0].size()) {}",
  85.           "",
  86.           "  static Matrix identity_matrix (int n) { ",
  87.           "     vector < vector <int> > values(n, vector <int> (n,0));",
  88.           "     for (int i=0; i<n; i++) values[i][i] = 1;",
  89.           "     return values;",
  90.           "  }",
  91.           "  Matrix operator* (const Matrix &other) const {",
  92.           "    int n = n_rows, m = n_cols;",
  93.           "    vector < vector <int> > result (n_rows, vector<int> (n_cols,0));",
  94.           "    for (int i=0; i<n; i++)",
  95.           "      for (int j=0; j<m; j++) {",
  96.           "        long long tmp = 0;",
  97.           "        for (int k=0; k < n_cols; k++) {",
  98.           "            tmp += mat[i][k] * 1ll * other.mat[k][j];",
  99.           "            while (tmp >= MOD2) tmp -= MOD2;",
  100.           "        }",
  101.           "        result[i][j] = tmp % MOD;",
  102.           "      }",
  103.           "    return move(Matrix(move(result)));",
  104.           "  } ",
  105.           "  inline bool is_square () const { return n_rows == n_cols;}",
  106.           "};",
  107.           "",
  108.           "Matrix pw (Matrix a, int p) {",
  109.           "  Matrix result = Matrix::identity_matrix(a.n_cols);",
  110.           "  while (p>0) {",
  111.           "    if (p&1) result = a*result;",
  112.           "    a = a*a;",
  113.           "    p >>= 1;",
  114.           "  }",
  115.           "  return result;",
  116.           "}"
  117.         ],
  118.         "description": ""
  119.       },
  120.       "template 3": {
  121.         "prefix": "bin_expo",
  122.         "body": [
  123.           "ll binpow(ll a, ll b, ll m) {",
  124.           "    a %= m;",
  125.           "    ll res = 1;",
  126.           "    while (b > 0) {",
  127.           "        if (b & 1)",
  128.           "            res = res * a % m;",
  129.           "        a = a * a % m;",
  130.           "        b >>= 1;",
  131.           "    }",
  132.           "    return res;",
  133.           "}"
  134.         ],
  135.         "description": ""
  136.       },
  137.       "DSU": {
  138.         "prefix": "dsu",
  139.         "body": [
  140.           "class DSU {",
  141.           "    vi p,rank;",
  142.           "    public :",
  143.           "    DSU(ll n) {",
  144.           "        p.resize(n+1,0),rank.resize(n+1,0);",
  145.           "        loop (i,0,n) p[i] = i;",
  146.           "    }",
  147.           "",
  148.           "    ll Get (ll a) {",
  149.           "        return p[a] = (p[a] == a) ? a : Get(p[a]);",
  150.           "    }",
  151.           "",
  152.           "    void Union (ll a, ll b) {",
  153.           "        a = Get(a), b = Get(b);",
  154.           "        if (a == b) return;",
  155.           "        if (rank[a] > rank[b])",
  156.           "            p[b] = a, rank[a]++;",
  157.           "        else",
  158.           "            p[a] = b, rank[b]++;",
  159.           "    }",
  160.           "};"
  161.         ],
  162.         "description": "DSU"
  163.       }
  164.     }
  165.    
Add Comment
Please, Sign In to add comment