Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- using str = string; // yay python!
- using pi = pair<int,int>;
- using pl = pair<ll,ll>;
- using pd = pair<db,db>;
- using vi = vector<int>;
- using vb = vector<bool>;
- using vl = vector<ll>;
- using vd = vector<db>;
- using vs = vector<str>;
- using vpi = vector<pi>;
- using vpl = vector<pl>;
- using vpd = vector<pd>;
- #define tcT template<class T
- #define tcTU tcT, class U
- // ^ lol this makes everything look weird but I'll try it
- tcT> using V = vector<T>;
- tcT, size_t SZ> using AR = array<T,SZ>;
- tcT> using PR = pair<T,T>;
- // pairs
- #define mp make_pair
- #define f first
- #define s second
- #define sz(x) (int)(x).size()
- // loops
- #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
- #define F0R(i,a) FOR(i,0,a)
- #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
- #define R0F(i,a) ROF(i,0,a)
- #define trav(a,x) for (auto& a: x)
- // INPUT
- #define tcTUU tcT, class ...U
- tcT> void re(complex<T>& c);
- tcTU> void re(pair<T,U>& p);
- tcT> void re(vector<T>& v);
- tcT, size_t SZ> void re(AR<T,SZ>& a);
- tcT> void re(T& x) { cin >> x; }
- void re(db& d) { str t; re(t); d = stod(t); }
- void re(ld& d) { str t; re(t); d = stold(t); }
- tcTUU> void re(T& t, U&... u) { re(t); re(u...); }
- tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
- tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
- tcT> void re(vector<T>& x) { trav(a,x) re(a); }
- tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }
- tcT> void rv(int& n, vector<T>& x) { re(n); x.rsz(n); trav(a,x) re(a); }
- // TO_STRING
- #define ts to_string
- str ts(char c) { return str(1,c); }
- str ts(const char* s) { return (str)s; }
- str ts(str s) { return s; }
- str ts(bool b) {
- #ifdef LOCAL
- return b ? "true" : "false";
- #else
- return ts((int)b);
- #endif
- }
- tcT> str ts(complex<T> c) {
- stringstream ss; ss << c; return ss.str(); }
- str ts(vector<bool> v) {
- str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
- res += "}"; return res; }
- template<size_t SZ> str ts(bitset<SZ> b) {
- str res = ""; F0R(i,SZ) res += char('0'+b[i]);
- return res; }
- tcTU> str ts(pair<T,U> p);
- tcT> str ts(T v) { // containers with begin(), end()
- #ifdef LOCAL
- bool fst = 1; str res = "{";
- for (const auto& x: v) {
- if (!fst) res += ", ";
- fst = 0; res += ts(x);
- }
- res += "}"; return res;
- #else
- bool fst = 1; str res = "";
- for (const auto& x: v) {
- if (!fst) res += " ";
- fst = 0; res += ts(x);
- }
- return res;
- #endif
- }
- tcTU> str ts(pair<T,U> p) {
- #ifdef LOCAL
- return "("+ts(p.f)+", "+ts(p.s)+")";
- #else
- return ts(p.f)+" "+ts(p.s);
- #endif
- }
- // OUTPUT
- tcT> void pr(T x) { cout << ts(x); }
- tcTUU> void pr(const T& t, const U&... u) {
- pr(t); pr(u...); }
- void ps() { pr("\n"); } // print w/ spaces
- tcTUU> void ps(const T& t, const U&... u) {
- pr(t); if (sizeof...(u)) pr(" "); ps(u...); }
- // DEBUG
- void DBG() { cerr << "]" << endl; }
- tcTUU> void DBG(const T& t, const U&... u) {
- cerr << ts(t); if (sizeof...(u)) cerr << ", ";
- DBG(u...); }
- #ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
- #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
- #define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
- << __FUNCTION__ << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
- #else
- #define dbg(...) 0
- #define chk(...) 0
- #endif
- // FILE I/O
- void setIn(str s) { freopen(s.c_str(),"r",stdin); }
- void setOut(str s) { freopen(s.c_str(),"w",stdout); }
- void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
- void setIO(str s = "") {
- unsyncIO();
- // cin.exceptions(cin.failbit);
- // throws exception when do smth illegal
- // ex. try to read letter into int
- if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
- }
- int main() {
- // setIO();
- {
- vector<bool> v = {0,1,1,0,1};
- ps(v);
- bitset<5> b; b[3] = 1;
- ps(b);
- }
- {
- int a = 1;
- ll b = 2;
- db c = 3;
- char d = '4';
- str e = "5";
- bool f = true;
- complex<double> g(1,2);
- ps("OK",a,b,c,d,e,f,g);
- }
- {
- pair<int, int> a = {1, 2};
- pair<string, bool> b = {"abcd", false};
- pair<char, float> c = {'x', 0.5};
- string d = "This is a string";
- pair<int, pair<int, int> > e = {1, {2, 3}};
- dbg(a, b, c, d, e);
- dbg();
- }
- {
- vector<int> a = {1, 2, 3, 4};
- set<int> b = {1, 2, 2, 3, 3, 4, 4, 5};
- map<string, int> c;
- c["string 1"] = 1;
- c["string 2"] = 2;
- dbg(a, b, c);
- unordered_map<string, int> d;
- d["string 3"] = 3;
- d["string 4"] = 4;
- multiset<int> e = {5, 5, 4, 3, 1, 1, 2};
- vector<vector<int> > f = {{1, 2, 3}};
- dbg(d, e, f);
- }
- {
- int a = 1;
- int b = 2;
- dbg(a + b, a * b, a / b, a - b, a / (float)b, 2019, 2019 - 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement