Last active
December 12, 2015 13:21
-
-
Save akouryy/7450d21b24aaa2bcbbaa to your computer and use it in GitHub Desktop.
競プロ用テンプレート(2015/11/23)
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
// C++ 11 | |
// Library | |
#include <bits/stdc++.h> | |
using namespace std; | |
// Type Name | |
#define TMPL template<class T> | |
#define TMPL2 template<class T, class U> | |
#define TMPL_A template<class T, class ...U> | |
TMPL using viter = typename vector<T>::iterator; | |
TMPL using vciter = typename vector<T>::const_iterator; | |
TMPL using remove_const_t = typename remove_const <T>::type; | |
TMPL using remove_reference_t = typename remove_reference<T>::type; | |
// Loop | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(remove_const_t<remove_reference_t<decltype(t)>> _##i = (t), i = (f); i <= _##i; i++) | |
#define uptil(f, t, i) for(remove_const_t<remove_reference_t<decltype(t)>> _##i = (t), i = (f); i < _##i; i++) | |
#define downto(f, t, i) for(remove_const_t<remove_reference_t<decltype(t)>> _##i = (t), i = (f); i >= _##i; i--) | |
#define downtil(f, t, i) for(remove_const_t<remove_reference_t<decltype(t)>> _##i = (t), i = (f); i > _##i; i--) | |
#define unless(c) if(!(c)) | |
#define until(c) while(!(c)) | |
#define loop while(true) | |
// I/O | |
#define ln << "\n" | |
#define tb << "\t" | |
#define sp << " " | |
TMPL istream& operator>>(istream& in, vector<T>& v) { times(v.capacity(), i) in >> v[i]; return in; } | |
TMPL ostream& operator<<(ostream& out, const vector<T>& v) { times(v.size(), i) out << (i ? " " : "") << v[i]; return out; } | |
TMPL2 istream& operator>>(istream& in, pair<T, U>& p) { T t; U u; in >> t >> u; p = pair<T, U>(t, u); return in; } | |
TMPL2 ostream& operator<<(ostream& out, const pair<T, U>& p) { out << p.first sp << p.second; return out; } | |
TMPL_A T next(istream& in, const U&... args) { T t(args...); in >> t; return t; } | |
TMPL_A T next( const U&... args) { return next<T>(cin, args...); } | |
string nextLine(istream& in = cin) { string s; getline(in, s); return move(s); } | |
struct {} nout; | |
TMPL decltype(nout) operator<<(decltype(nout) no, const T& t) { return no; } | |
#ifdef debug | |
#define dout cout | |
#else | |
#define dout nout | |
#endif | |
// Math | |
TMPL T pow (T x, T n) { int ans = 1; while(n) { if(n & 1) ans *= x; x *= x; n /= 2; } return ans; } | |
TMPL T pow_mod(T x, T n, T mod) { int ans = 1; while(n) { if(n & 1) { ans *= x; ans %= mod; } x *= x; x %= mod; n /= 2; } return ans; } | |
TMPL T div_modP(T d, T r, T modP) { return d * pow_mod(r, modP - 2, modP) % modP; } | |
// Vector Operation | |
#define all(v) begin(v), end(v) | |
// Calculation | |
/* | |
TMPL T sum (const viter<T>& begin, const viter<T>& end) { T ans = T(); for(viter<T> t = begin; t != end; t++) ans += *t; return ans; } | |
TMPL T sum_mod (const viter<T>& begin, const viter<T>& end, T mod) { T ans = T(); for(viter<T> t = begin; t != end; t++) ans = (ans + *t) % mod; return ans; } | |
TMPL T product (const viter<T>& begin, const viter<T>& end) { T ans = T(); for(viter<T> t = begin; t != end; t++) ans *= *t; return ans; } | |
TMPL T product_mod(const viter<T>& begin, const viter<T>& end, T mod) { T ans = T(); for(viter<T> t = begin; t != end; t++) ans = (ans * *t) % mod; return ans; } | |
TMPL T min (const viter<T>& begin, const viter<T>& end) { return *min_element(begin, end); } | |
TMPL T min_index (const viter<T>& begin, const viter<T>& end) { return distance(begin, min_element(begin, end)); } | |
TMPL T max (const viter<T>& begin, const viter<T>& end) { return *max_element(begin, end); } | |
TMPL T max_index (const viter<T>& begin, const viter<T>& end) { return distance(begin, max_element(begin, end)); } | |
*/ | |
TMPL T sum (const vector<T>& v) { T ans = T(); for(const T& t : v) ans += t; return ans; } | |
TMPL T sum_mod (const vector<T>& v, T mod) { T ans = T(); for(const T& t : v) ans = (ans + t) % mod; return ans; } | |
TMPL T product (const vector<T>& v) { T ans = T(); for(const T& t : v) ans *= t; return ans; } | |
TMPL T product_mod(const vector<T>& v, T mod) { T ans = T(); for(const T& t : v) ans = (ans * t) % mod; return ans; } | |
TMPL T min (const vector<T>& v) { return *min_element(all(v)); } | |
TMPL T min_index (const vector<T>& v) { return distance(begin(v), min_element(all(v))); } | |
TMPL T max (const vector<T>& v) { return *max_element(all(v)); } | |
TMPL T max_index (const vector<T>& v) { return distance(begin(v), max_element(all(v))); } | |
// All of Vector | |
/* | |
TMPL inline T sum (const vector<T>& v) { return sum <T>(all_unconst(v)); } | |
TMPL inline T sum_mod (const vector<T>& v, T mod) { return sum_mod <T>(all_unconst(v), mod); } | |
TMPL inline T product (const vector<T>& v) { return product <T>(all_unconst(v)); } | |
TMPL inline T product_mod(const vector<T>& v, T mod) { return product_mod<T>(all_unconst(v), mod); } | |
TMPL inline T min (const vector<T>& v) { return min <T>(all_unconst(v)); } | |
TMPL inline T min_index (const vector<T>& v) { return min_index <T>(all_unconst(v)); } | |
TMPL inline T max (const vector<T>& v) { return max <T>(all_unconst(v)); } | |
TMPL inline T max_index (const vector<T>& v) { return max_index <T>(all_unconst(v)); } | |
*/ | |
TMPL inline void sort ( vector<T>& v) { sort<viter<T>>(all(v)); } | |
// Immutable | |
TMPL inline vector<T> sorted(vector<T> v) { sort(v); return v; } | |
// Compound Assignment | |
TMPL inline bool maxA (T& a, const T& b) { if(a < b) { a = b; return true; } else return false; } | |
TMPL inline bool maxEA(T& a, const T& b) { if(a <= b) { a = b; return true; } else return false; } | |
TMPL inline bool minA (T& a, const T& b) { if(a > b) { a = b; return true; } else return false; } | |
TMPL inline bool minEA(T& a, const T& b) { if(a >= b) { a = b; return true; } else return false; } | |
TMPL inline bool maxS (T& a, T& b) { if(a < b) { swap(a, b); return true; } else return false; } | |
TMPL inline bool maxES(T& a, T& b) { if(a <= b) { swap(a, b); return true; } else return false; } | |
TMPL inline bool minS (T& a, T& b) { if(a > b) { swap(a, b); return true; } else return false; } | |
TMPL inline bool minES(T& a, T& b) { if(a >= b) { swap(a, b); return true; } else return false; } | |
TMPL inline void maxminA(T& max, T& min, const T& a, const T& b) { max = a > b ? a : b; min = a < b ? a : b; } | |
TMPL inline void minmaxA(T& min, T& max, const T& a, const T& b) { max = a > b ? a : b; min = a < b ? a : b; } | |
int main() { | |
ios::sync_with_stdio(false); | |
cin.tie(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment