Skip to content

Instantly share code, notes, and snippets.

@Eyakub
Forked from ArifHosan/template.cpp
Created August 23, 2016 19:29
Show Gist options
  • Save Eyakub/fb7bebfac84b6876d692bb5c191f8093 to your computer and use it in GitHub Desktop.
Save Eyakub/fb7bebfac84b6876d692bb5c191f8093 to your computer and use it in GitHub Desktop.
CPP contest template
/*
Name: Md. Nabid Imteaj
Prob:
Algo:
*/
#pragma comment( linker, "/STACK:16777216" )
#pragma warning( disable:4786 )
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
using namespace std;
// debug
// credit: smilitude
#define D(x) if(iDeBug) cout << __LINE__ << " " << #x" = " << (x) << endl
#define D2(x,y) if(iDeBug) cout << __LINE__ << " " << #x" = " << (x) \
<< ", " << #y" = " << (y) << endl
#define READ(f) freopen( (f), "r", stdin )
#define WRITE(f) freopen( (f), "w", stdout )
#define mset(x,n) memset((x),(n),sizeof((x)))
#ifdef _WIN32
#define LLId "%I64d"
#else
#define LLId "%lld"
#endif // _WIN32
#define pf(x) cout << (x)
#define pfl(x) cout << (x) << endl
#define pfln() cout << endl
#define pfs() cout << " "
#define take_i(_x) scanf("%d", &_x)
#define take_ui(_x) scanf("%u", &_x)
#define take_LL(_x) scanf(LLId, &_x)
#define take_ULL(_x) scanf(LLId, &_x)
#define take_c(_x) scanf("%c", &_x)
#define take_d(_x) scanf("%lf", &_x)
#define take_s(_x) scanf("%s", _x)
#define FOR(i,a,b) for(int i=(a),_e(b); i<=_e; i++)
#define REV(i,a,b) for(int i=(a),_e(b); i>=_e; i--)
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector< PII > VII;
template<class T> inline T MAX( T a, T b ) { return a>b?a:b; }
template<class T> inline T MIN( T a, T b ) { return a<b?a:b; }
template<class T> inline void SWAP( T &a, T &b ) { a=a^b; b=a^b; a=a^b; }
template<class T, class T1>inline void Reverse( T1 A[], T i, T j ) { for( ; i<j; i++,j-- ) SWAP( A[i], A[j] ); }
template<class T> inline T fAbs( T a ) { return a<0?a*(-1):a; }
template<class T> inline T GCD(T a, T b) { if(a<0) return GCD(-a,b); if(b<0)return GCD(a,-b); while(b){b^=a^=b^=a%=b;} return a; }
template<class T> inline T LCM(T a, T b) { return a/GCD(a,b)*b; }
inline int BigMod(int a, int p, int M) {
int res = 1, x = a;
while(p) { if(p&1) res = ((LL)res * x) % M; x = ((LL)x * x) % M; p >>= 1; }
return res;
}
LL POW(const int &n, const int &k) { LL res = 1; FOR(i, 0, k-1) res *= n; return res; }
class Converter {
public:
/*parse integer from string*/
static inline int parseInt(const char *str) {
int ten = 1, len = strlen(str), res = 0, st;
str[0] == '-' ? st = 1 : st = 0;
REV(i, len-1, st) { res += (int)(str[i] - '0') * ten; ten *= 10; }
if(st) res *= -1;
return res;
}
template<class T>static inline string toString(T num, const int base) {
int res = -1, rem;
string str = "";
char ch = '\0';
while(res != 0) { res = num / base; rem = num % base; num = res; rem>9?ch=(rem-10)+'A':ch=rem+'0'; str.append(1, ch); }
reverse(str.begin(), str.end());
return str;
}
template<class T>static inline string toString(const T num) { return toString(num, 10); }
template<class T>static inline string decimalToBinary(const T num) {return toString(num, 2);}
template<class T>static inline string decimalToHex(const T num) {return toString(num, 16);}
template<class T>static inline string decimalToOctal(const T num) {return toString(num, 8);}
static inline int toDecimal(const char *str, const int &base) {
int res = 0, tmp;
int len = strlen(str), k = 0;
char ch;
FOR(i, 0, len-1) {
ch = toUpper( str[len-(i+1)] );
ch >= '0' && ch <= '9'? tmp = (int)(ch-'0') : tmp = (int)(ch-'A' + 10);
res += tmp * POW(base, i);
}
return res;
}
static inline int binaryToDecimal(const char *str) { return toDecimal(str, 2); }
static inline int hexToDecimal(const char *str) { return toDecimal(str, 16); }
static inline int octalToDecimal(const char *str) { return toDecimal(str, 8); }
static inline int toUpper(char ch) { return ch>='a'&&ch<='z'? ch=ch-'a'+'A':ch; }
static inline int toLower(char ch) { return ch>='A'&&ch<='Z'? ch=ch-'A'+'a':ch; }
};
class BitMan {
private:
template<class T>static inline T _help_getXOR(T a) { T res[] = {a,1,a+1,0}; return res[a%4]; }
public:
/* Returns maximum XOR in range l to r (inclusive) */
template<class T>static inline T maxXOR(T l, T r) { T q = l ^ r, a = 1; while(q){ q >>= 1; a <<= 1; } return --a; }
/* Get XOR between range l to r (inclusive) */
template<class T>static inline T getXOR(T l, T r) { return _help_getXOR(r)^_help_getXOR(l-1); }
};
const int SZ = 1e4+10;
const int INF = 1<<29;
const double PI = 2*acos(0.0);
const double EPS = 1e-9;
int main( ) {
#define iDeBug 0
//#define fDeBug
//#define CF_Loop
#ifdef fDeBug
READ( "in.txt" );
// WRITE( "out.txt" );
#endif
#ifdef CF_Loop
while( 1 ) {
#endif // CF_Loop
int tc, caseno = 1;
// MAKE SURE "iDeBug" IS SET TO "0" BEFORE SUBMIT
#ifdef CF_Loop
}
#endif // CF_Loop
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment