1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include "bits/stdc++.h" using namespace std;
#define all(a) (a).begin(), (a).end() template<typename T, typename F=less<T>> using pque=priority_queue<T, vector<T>, F>; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; typedef vector<vs> vvs;
template <typename T> T max(const T& a, const T& b, const T& c) { return max(max(a, b), c); } template <typename T> T max(const vector<T>& a) {T r = a[0]; for(auto e : a) r = max(r, e); return r;} template <typename T> T min(const T& a, const T& b, const T& c) { return min(min(a, b), c); } template <typename T> T min(const vector<T>& a) {T r = a[0]; for(auto e : a) r = min(r, e); return r;} template<typename T> T sum(const vector<T>& a) { T r = 0; for(auto& e : a) r+=e; return r;} template<typename T> T gcd(T a, T b) { while(b) { T r = a%b; a = b; b = r;} return a;} template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; } template<typename F> ll lb(ll b, ll e, F f) {if(b>=e) return e; while(b<e-1) {auto m=b+(e-1-b)/2; if(!f(m)) b=m+1; else e=m+1;} return f(b)?b:e;} template<typename T> struct cast_helper {T operator() (stringstream& ss) {T r=T{}; ss >> r; return r;}}; template<> struct cast_helper<string> {string operator() (stringstream& ss) { return ss.str();}}; template<typename R, typename T> R sstream_cast(const T& o) {stringstream ss; ss << o; return cast_helper<R>()(ss);} string fmt(const char* f, ...){va_list a; va_start(a, f); char b[4096]; vsnprintf(b, 4096, f, a); va_end(a); return b;}
vvi make_vvi(int n, int m, int v=0) { return vvi(n, vi(m, v));} vvb make_vvb(int n, int m, bool v=false) { return vvb(n, vb(m, v));} vvs make_vvs(int n, int m, const string& v="") { return vvs(n, vs(m, v));} typedef tuple<ll, ll> tii; typedef tuple<int, int, int> tiii; namespace std { template<>struct hash<tii>{size_t operator()(const tii& a)const {return get<0>(a)^get<1>(a);}}; template<>struct hash<tiii>{size_t operator()(const tiii& a)const {return get<0>(a)^get<1>(a)^get<2>(a);}}; }; tii dir4[] = {tii(-1, 0), tii(0, 1), tii(1, 0), tii(0,-1)}; tii dir8[] = {tii(-1, 0), tii(0, 1), tii(1, 0), tii(0,-1), tii(-1,-1), tii(-1,1), tii(1,1), tii(1,-1)}; tii& operator += (tii& a, const tii& b) { get<0>(a)+=get<0>(b); get<1>(a)+=get<1>(b); return a; } tii operator + (const tii& a, const tii& b) { return tii(get<0>(a)+get<0>(b), get<1>(a)+get<1>(b)); } tii& operator -= (tii& a, const tii& b) { get<0>(a)-=get<0>(b); get<1>(a)-=get<1>(b); return a; } tii operator - (const tii& a, const tii& b) { return tii(get<0>(a)-get<0>(b), get<1>(a)-get<1>(b)); } tii operator - (const tii& a) { return tii(-get<0>(a), -get<1>(a)); } tii& operator *= (tii& a, int k) { get<0>(a)*=k; get<1>(a)*=k; return a; } tii operator * (int k, const tii& a) { return tii(k*get<0>(a), k*get<1>(a)); } tii operator * (const tii& a, int k) { return tii(get<0>(a)*k, get<1>(a)*k); } tii& operator /= (tii& a, int k) { get<0>(a)/=k; get<1>(a)/=k; return a; } tii operator / (const tii& a, int k) { return tii(get<0>(a)/k, get<1>(a)/k); } bool in_range(tii p, tii e) {return 0<=get<0>(p)&&get<0>(p)<get<0>(e)&&0<=get<1>(p)&&get<1>(p)<get<1>(e);} bool in_range(tii p, tii b, tii e) {return get<0>(b)<=get<0>(p)&&get<0>(p)<get<0>(e)&&get<1>(b)<=get<1>(p)&&get<1>(p)<get<1>(e);}
#ifndef cout struct _ { template <typename T> _& operator << (const T&){ return *this; } }; #define cout _() #define endl '\n' #endif
int _main_() { return 0; }
#undef cout #undef endl
|