Skip to content

Instantly share code, notes, and snippets.

@theSoberSobber
Created January 31, 2023 18:33
Show Gist options
  • Save theSoberSobber/3e10669cb4e1dcf70550a9122735228a to your computer and use it in GitHub Desktop.
Save theSoberSobber/3e10669cb4e1dcf70550a9122735228a to your computer and use it in GitHub Desktop.
snippets
{
"bp": {
"prefix": "bp",
"body": [
"#include <bits/stdc++.h>",
"#ifndef ONLINE_JUDGE",
"#include \"debug.h\"",
"#else",
"#define dbg(x...)",
"#endif",
"",
"using namespace std;",
"",
"#define ll long long int",
"#define loop(i,a,b) for(int i=a;i<b;i++)",
"",
"void pre_process(){",
" ",
"}",
"",
"int solve(){",
" int n; cin>>n;",
" dbg(n);",
" return 2*n; ",
"}",
"int32_t main(){",
" ios_base::sync_with_stdio(0);",
" cin.tie(0); cout.tie(0);",
" pre_process();",
" int t; cin>>t;",
" while(t--) cout<<solve()<<'\\n';",
"}"
],
"description": "bp"
},
"pbds" : {
"prefix": "pbds",
"body": [
"#include <ext/pb_ds/assoc_container.hpp>",
"#include <ext/pb_ds/tree_policy.hpp>",
"using namespace __gnu_pbds;",
"typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> op_set;\n"
],
"description": "pbds"
},
"binpow" : {
"prefix": "binpow",
"body": [
"ll binpow(ll x, ll y){",
"\t// iterative binary exponentiation",
"\tll res = 1;",
"\twhile (y > 0) {",
"\tif (y & 1) res = (long long)(res*x); // adding powers wherever bit is set",
"\ty = y>>1;",
"\tx = (long long)(x*x); // increasing power by 2",
"\t}" ,
"\treturn res;" ,
"}\n"
],
"description": "binpow"
},
"bits" : {
"prefix": "bits",
"body": [
"#define "
],
"description": "bits"
},
"mint": {
"prefix": "mint",
"body": [
"struct mi {",
" int64_t v; explicit operator int64_t() const { return v % mod; }",
" mi() { v = 0; }",
" mi(int64_t _v) {",
" v = (-mod < _v && _v < mod) ? _v : _v % mod;",
" if (v < 0) v += mod;",
" }",
" friend bool operator==(const mi& a, const mi& b) {",
" return a.v == b.v; }",
" friend bool operator!=(const mi& a, const mi& b) {",
" return !(a == b); }",
" friend bool operator<(const mi& a, const mi& b) {",
" return a.v < b.v; }",
"",
" mi& operator+=(const mi& m) {",
" if ((v += m.v) >= mod) v -= mod;",
" return *this; }",
" mi& operator-=(const mi& m) {",
" if ((v -= m.v) < 0) v += mod;",
" return *this; }",
" mi& operator*=(const mi& m) {",
" v = v*m.v%mod; return *this; }",
" mi& operator/=(const mi& m) { return (*this) *= inv(m); }",
" friend mi pow(mi a, int64_t p) {",
" mi ans = 1; assert(p >= 0);",
" for (; p; p /= 2, a *= a) if (p&1) ans *= a;",
" return ans;",
" }",
" friend mi inv(const mi& a) { assert(a.v != 0);",
" return pow(a,mod-2); }",
"",
" mi operator-() const { return mi(-v); }",
" mi& operator++() { return *this += 1; }",
" mi& operator--() { return *this -= 1; }",
" mi operator++(int32_t) { mi temp; temp.v = v++; return temp; }",
" mi operator--(int32_t) { mi temp; temp.v = v--; return temp; }",
" friend mi operator+(mi a, const mi& b) { return a += b; }",
" friend mi operator-(mi a, const mi& b) { return a -= b; }",
" friend mi operator*(mi a, const mi& b) { return a *= b; }",
" friend mi operator/(mi a, const mi& b) { return a /= b; }",
" friend ostream& operator<<(ostream& os, const mi& m) {",
" os << m.v; return os;",
" }",
" friend istream& operator>>(istream& is, mi& m) {",
" int64_t x; is >> x;",
" m.v = x;",
" return is;",
" }",
" friend void __print(const mi &x) {",
" cerr << x.v;",
" }",
"};",
""
],
"description": ""
},
"seive": {
"prefix": "seive",
"body": [
"vector<bool> Prime;",
"vector<int> spf;",
"void sieve(int s = maxn) {",
" Prime.resize(s + 1, 1);",
" spf.resize(s + 1, s + 1);",
" for(int i = 2 ; i <= s ; i++) if(Prime[i]) {",
" spf[i] = min(spf[i], i);",
" for(int j = i ; (ll)j * i <= s ; j++)",
" Prime[j * i] = 0, spf[j * i] = min(i, spf[j * i]);",
" }",
"}",
""
],
"description": "seive"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment