Advertisement
sleepy_coder

competitive.hpp

May 1st, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/detail/standard_policies.hpp>
  5. using namespace   std;
  6. using namespace __gnu_cxx;
  7. using namespace __gnu_pbds;
  8.  
  9. typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll;
  10. typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<pll> vll;
  11. typedef map<ll, ll> mii; typedef map<string, ll> msi; typedef vector< vi > vvi;
  12.  
  13. #define     sz                 size()
  14. #define     pb                 push_back
  15. #define     inf                (1<<30)
  16. #define     mod                (1000000007)
  17. #define     pi                 (acos(-1.0))
  18. #define     all(x)             x.begin(), x.end()
  19. #define     mem(a,b)           memset((a), (b), sizeof(a));
  20. #define     _unique(c)         (c).resize(unique(all(c)) - (c).begin())
  21. #define     fast_io            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  22. #define     what_is(x)         cerr << #x << " is " << x << endl;
  23. #define     rep(i, n)          for(__typeof(n) i=0; i<(n); i++)
  24. #define     foab(i, a, b)      for(__typeof(b) i=(a); i<=(b); i++)
  25. #define     foba(i, a, b)      for(__typeof(b) i=(b); i>=(a); i--)
  26. #define     foch(it, l)        for(__typeof((l).begin()) it = begin(l);  it != end(l); it++)
  27. #define     d_value(x)         cout<<fixed<<setprecision(x);
  28. #define     file_io            {                                        \
  29.                                     freopen("input.txt", "r", stdin);   \
  30.                                     freopen("output.txt", "w", stdout); \
  31.                                }
  32. #define error(args...) {                                                            \
  33.         string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');                 \
  34.         stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);    \
  35.         }
  36.  
  37. void err(istream_iterator<string> it) {}                 template<typename T, typename... Args>
  38. void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); }
  39.  
  40. inline ll bigMul(ll a,ll b,ll m){
  41.     ll result = 0; a %= m;
  42.     while(b) { if(b&1LL) result=(result+a)%m; a=(a+a)%m; b>>=1; }
  43.     return result;
  44. }
  45.  
  46. ll bigMod(ll b, ll e, ll m){
  47.     if(!e)return 1%m;
  48.     if(!(e&1LL)){ ll y = bigMod(b, e>>1LL, m); return bigMul(y, y, m); }
  49.     ll z = bigMod(b, e-1, m); return (bigMul(b%m, z, m));
  50. }
  51.  
  52. /**Define BitWise operation**/
  53. bool checkBit(int n, int pos) { return (n & (1<<pos)) != 0; }
  54. inline int setBit(int n, int pos) {return (n | (1<<(pos))); }
  55. inline int resetBit(int n, int pos) { return (n & ~(1<<(pos))); }
  56. inline void printBits(int n){ if(n >= 2)printBits(n/2); cout<<(n&1); }
  57. inline int countOnes(int n) { int r=0; while(n && ++r) n -= n&(-n); return r; }
  58.  
  59. template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  60. template <typename T>
  61. string toString(T n) { stringstream ss; ss << n; return ss.str(); }
  62. template< typename T >
  63. T exEuclid(T a, T b, T& x, T& y) {
  64.     if(!b){ x = 1, y = 0; return a; }
  65.     T x1, y1, temp = exEuclid<T>(b, a%b, x1, y1);
  66.     x = y1, y = x1 - y1*(a/b);
  67.     return temp;
  68. }
  69. template< typename T >
  70. inline T modInverse(T a, T m){ T x, y; T g = exEuclid<T>(a, m, x, y); if(g != 1){ return -1; } else{ return (x%m + m)%m; } }
  71. template<typename T> ostream&
  72. operator<<(ostream& os, const vector<T> &t) { ll n = t.size(); rep(i, n) os<<t[i]<<" "; return os; }
  73. template<typename T,typename TT>
  74. ostream& operator<<(ostream &os, const pair<T,TT> &t) { return os<<"("<<t.first<<","<<t.second<<")"; }
  75.  
  76. enum COLOR{ white=1 , grey=2 , black=3, red = 4, green = 5, blue = 6 };
  77.  
  78. vii dir_4 {{1,0}, {0,1}, {-1,0}, {0,-1}};
  79. vii dir_8 {{0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}};
  80. vii dir_knight {{2,1}, {1,2}, {-1,2}, {-2,1}, {-2,-1}, {-1,-2}, {1,-2}, {2,-1}};
  81. //-------------- ---------------- ----------------- --------------- ------------ ----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement