Last active
May 27, 2020 06:18
-
-
Save PalashBansal/a3dc3a94f8eaf1e7fe130b20eed8bac7 to your computer and use it in GitHub Desktop.
competitive programming cpp template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> // precompiled header (may not be supported by execution environment) | |
#include <iostream> | |
#include <sstream> | |
#include <cstdio> | |
#include <cmath> | |
#include <cstring> | |
#include <cctype> | |
#include <string> | |
#include <vector> | |
#include <list> | |
#include <set> | |
#include <map> | |
#include <queue> | |
#include <stack> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
#define DEBUG(x) cout << '>' << #x << ':' << x << endl; | |
typedef long long ll; | |
typedef unsigned long long int ulli; | |
typedef ll ndt;//"new datatype"(change ll to ulli here) | |
#define REP(i,n) for(ndt i=0;i<(n);++i) | |
#define FOR(i,a,b) for(ndt i=(a);i<=(b);++i) | |
#define FORD(i,a,b) for(ndt i=(a);i>=(b);--i) | |
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; } | |
const int INF = 1<<29; | |
inline int two(int n) { return 1 << n; } | |
inline int test(int n, int b) { return (n>>b)&1; } | |
inline void set_bit(int & n, int b) { n |= two(b); } | |
inline void unset_bit(int & n, int b) { n &= ~two(b); } | |
inline int last_bit(int n) { return n & (-n); } | |
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; } | |
template<class T> void chmax(T & a, const T & b) { a = max(a, b); } | |
template<class T> void chmin(T & a, const T & b) { a = min(a, b); } | |
inline ndt frndt()//fastRead_ll(); | |
{ | |
register char c=0; | |
while (c<33) c=getchar_unlocked(); | |
ndt a=0; | |
while (c>33) | |
{ | |
a=a*10+c-'0'; | |
c=getchar_unlocked(); | |
} | |
return a; | |
} | |
// usage: fastRead_ll(&N); N=frndt(); | |
/*#define gc() getchar_unlocked() | |
int isSpaceChar(char c) { | |
return (c == ' ' || c == '\n' || c == '\r') ; | |
} | |
inline ndt frndt()//FAST_IO() | |
{ | |
char ch; | |
ndt val=0LL; | |
ch=gc(); | |
while(isSpaceChar(ch)) | |
ch=gc(); | |
while(!isSpaceChar(ch)) | |
{ | |
val=(val*10)+(ch-'0'); | |
ch=gc(); | |
} | |
return val; | |
} | |
//usage: N = frndt(); | |
*/ | |
#define pc(x) putchar_unlocked(x); | |
/*inline void fwndt(ndt n)//writeInt (int n) | |
{ | |
ndt N = n, rev, count = 0; | |
rev = N; | |
if (N == 0) { pc('0'); pc('\n'); return ;} | |
while ((rev % 10) == 0) { count++; rev /= 10;} //obtain the count of the number of 0s | |
rev = 0; | |
while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;} //store reverse of N in rev | |
while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;} | |
while (count--) pc('0'); | |
}*/ | |
inline void fwndt(ndt n) | |
{ | |
if (n == 0) | |
{ | |
pc('0'); | |
pc('\n'); | |
} | |
else if (n == -1) | |
{ | |
pc('-'); | |
pc('1'); | |
pc('\n'); | |
} | |
else | |
{ | |
char buf[11]; | |
buf[10] = '\n'; | |
int i = 9; | |
while (n) | |
{ | |
buf[i--] = n % 10 + '0'; | |
n /= 10; | |
} | |
while (buf[i] != '\n') | |
pc(buf[++i]); | |
} | |
} | |
//usage: fwndt(n); | |
///////////////////////////////////////////////////////////////////// | |
int main() | |
{ | |
return 0; | |
} |
If you are not sure about some idea/improvement, feel free to comment here.
For a better template, pls put a link in comment.
Open for discussions!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please suggest anything related to this C++/C template which can be helpful for competitive programming, like redundant code, better alternatives.
Performance improvements will be highly appreciated.
Feel free to use this template for your use.