Skip to content

Instantly share code, notes, and snippets.

@offchan42
Created October 20, 2015 15:08
Show Gist options
  • Save offchan42/20710024bd6e2ef6a709 to your computer and use it in GitHub Desktop.
Save offchan42/20710024bd6e2ef6a709 to your computer and use it in GitHub Desktop.
My ACM ICPC Template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1001001001 // 1 billion, safer than 2B for Floyd Warshall’s
#define EPS 1e-9
// keyboard shortcuts
#define mp make_pair // useful for working with pairs
#define fi first
#define se second
#define pb push_back
#define endl '\n'
// Useful container manipulation / traversal macros
#define forall(i,a,b) for(int i=a;i<b;++i)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vpresent(c,x) (find(all(c),x) != (c).end()) // vector find
#define present(c,x) ((c).find(x) != (c).end()) // set|map find
#define clr(a,v) memset(a, v, sizeof a)
#define sz(a) ((int)(a.size()))
// Input macros
#define si(n) scanf("%d",&n)
#define sc(n) scanf("%c",&n)
#define sl(n) scanf("%lld",&n)
#define sf(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
// Output macros (Requires forall and sz definition)
#define pa(a, n) { forall(_tmp_pa, 0, n) cout << a[_tmp_pa] << ' '; cout << endl; }
#define pv(v) pa(v, sz(v))
#define paa(aa, n, m) forall(_tmp_paa, 0, n) pa(aa[_tmp_paa], m)
#define pav(av, n) forall(_tmp_pav, 0, n) pv(av[_tmp_pav])
#define pvv(vv) forall(_tmp_pvv, 0, sz(vv)) pv(vv[_tmp_pvv])
// Useful hardware instructions
#define bitcount __builtin_popcount // count binary one bits
#define lsb_index(num) __builtin_ctz(num) // count trailing zeros, least significant bit
#define msb_index(num) __builtin_clz(num) // count leading zeros, most significant bit
#define gcd __gcd // greatest common divisor
// maths
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define digits(i) (int)((log(i)/log(10))+1) //get number of digits
#define dround(num) (int)floor(num+0.5) // Round float to its nearest int
// Bitmask manipulation macros in C++ (Faster than bitset)
#define isOn(S, j) ((S >> j) & 1)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1)) // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
void read() {}
void solve() {}
int main() {
int TC = 1;
//si(TC);
while (TC--) {
read();
solve();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment