SorahISA

C++ template

Dec 26th, 2021 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.19 KB | None | 0 0
  1. #ifdef local
  2. #define _GLIBCXX_DEBUG 1
  3. #endif
  4. #pragma GCC optimize("Ofast", "unroll-loops")
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. #define int long long
  9. #define double long double
  10. using pii = pair<int, int>;
  11. template <typename T>
  12. using Prior = std::priority_queue<T>;
  13. template <typename T>
  14. using prior = std::priority_queue<T, vector<T>, greater<T>>;
  15.  
  16. #define X first
  17. #define Y second
  18. #define eb emplace_back
  19. #define ef push_front
  20. #define ee emplace
  21. #define pf pop_front
  22. #define pb pop_back
  23. #define ALL(x) begin(x), end(x)
  24. #define RALL(x) rbegin(x), rend(x)
  25. #define SZ(x) (int)(x).size()
  26.  
  27. #ifdef local
  28. #define debug(...) \
  29.     _color.eb("\u001b[31m"),\
  30.     cerr << _color.back() << "In function '" << __FUNCTION__ << "', line " << __LINE__ << ": (" << #__VA_ARGS__ << ") = ",\
  31.     _do(__VA_ARGS__),\
  32.     _color.pb(),\
  33.     cerr << _color.back()
  34. #define fastIO()
  35. deque<string> _color{"\u001b[0m"};
  36.  
  37. template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
  38. template <typename T> concept is_iterable = requires (T _t) {begin(_t);};
  39.  
  40. template <typename T> inline void _print_err(T &&_t) {cerr << _t;}
  41. template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
  42.     string _tmp_color = _color.back();
  43.     ++_tmp_color[3], _color.eb(_tmp_color);
  44.     cerr << _color.back() << "[";
  45.     for (bool _first = true; auto &_x : _t) {
  46.         if (!_first) cerr << ", ";
  47.         _print_err(_x), _first = false;
  48.     }
  49.     cerr << "]" << (_color.pb(), _color.back());
  50. }
  51.  
  52. template <typename T, typename U> ostream& operator << (ostream &os, pair<T, U> &_tu) {
  53.     string _tmp_color = _color.back();
  54.     ++_tmp_color[3], _color.eb(_tmp_color);
  55.     cerr << _color.back() << "(";
  56.     _print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
  57.     cerr << ")" << (_color.pb(), _color.back());
  58.     return os;
  59. }
  60.  
  61. template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
  62.     cerr << ")" << (_color.pb(), _color.back());
  63. }
  64.  
  65. template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
  66.     if (!I) {
  67.         string _tmp_color = _color.back();
  68.         ++_tmp_color[3], _color.eb(_tmp_color);
  69.         cerr << _color.back();
  70.     }
  71.     cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
  72. }
  73.  
  74. template <typename T> inline void _do(T &&_t) {_print_err(_t), cerr << "\n";}
  75. template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) {_print_err(_t), cerr << ", ", _do(_u...);}
  76. #else
  77. #define debug(...) void()
  78. #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
  79. #endif
  80.  
  81. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  82.  
  83. inline int getRand(int L, int R) {
  84.     if (L > R) swap(L, R);
  85.     return (int)(rng() % ((uint64_t)R - L + 1) + L);
  86. }
  87.  
  88. template <typename T> bool chmin(T &lhs, T rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
  89. template <typename T> bool chmax(T &lhs, T rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
  90.  
  91. void solve() {
  92.    
  93.     cout << "meow\n";
  94.    
  95.     vector<int> v = {1, 2};
  96.     string S = "string";
  97.     debug(3, v, string("test"), S, v);
  98.    
  99.     basic_string<int> s = {3, 4};
  100.     debug(s, s+s, s+1LL);
  101.    
  102.     vector<vector<int>> vv = {{1, 2}, {3, 4, 5}, {}, {6}, {7, 8, 9}};
  103.     debug(vv);
  104.    
  105.     vector<vector<vector<vector<double>>>> vvvv = {{{{1}}, {}, {{1.1}, {1.11}, {1.111}}}, {}, {{{1.1111}}}, {{{1.11111}}, {{1.111111}}}};
  106.     debug(vvvv);
  107.    
  108.     list<list<list<list<list<list<int>>>>>> llllll = {{{{{{0}}}}}};
  109.     debug(llllll);
  110.    
  111.     set<int> st = {1, 2, 2, 6, -1};
  112.     map<string, int> mp = {{"rk", 42745417}, {"tmwilliamlin", 168}, {"yp", 155136}, {"coldEr", 66}, {"erd", 1}};
  113.     unordered_multiset<int> umst = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9};
  114.     debug(st, mp, umst);
  115.    
  116.     pair<int, int> p1 = {-1, -2};
  117.     pair<double, char> p2 = {2.718, 'e'};
  118.     pair<pair<int, float>, pair<pair<int, char>, double>> p3 = {{6, 0.01}, {{99, 'X'}, 71.22}};
  119.     debug(p1, p2, p3);
  120.    
  121.     tuple<int, double, int, string> t1 = {-3, 3.14, -4, "tuple"};
  122.     tuple<pair<int, char>, vector<bitset<3>>, array<pair<int, int>, 3>> t2 = {
  123.         {1, 'A'},
  124.         {bitset<3>("110"), bitset<3>("000"), bitset<3>("111")},
  125.         {pii{2, 3}, pii{4, 5}, pii{6, 7}}
  126.     };
  127.     debug(t1, t2);
  128.    
  129.     list<int> l = {-1, -2, -3};
  130.     debug(l);
  131.    
  132.     debug("test normal", "test string"s, "debug(\"test recursive\")"s);
  133.    
  134.     debug("bin"s, 0b110, "hex"s, 0xdeadbeef, "oct"s, 01000, "dec"s, 1024);
  135.    
  136.     // not compiling
  137.     // debug();
  138.    
  139.     // not working properly (for sure)
  140.     // list<string> l_color = {"\u001b[31m", "\u001b[32m", "\u001b[33m", "\u001b[34m", "\u001b[35m", "\u001b[36m", "\u001b[37m"};
  141.     // debug(l);
  142.    
  143. }
  144.  
  145. int32_t main() {
  146.     fastIO();
  147.    
  148.     int t = 1; // cin >> t;
  149.     for (int _ = 1; _ <= t; ++_) {
  150.         // cout << "Case #" << _ << ": ";
  151.         solve();
  152.     }
  153.    
  154.     return 0;
  155. }
  156.  
  157. /*
  158. /// Fast I/O by FHVirus ///
  159. /// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
  160.  
  161. #include <unistd.h>
  162.  
  163. const int S = 65536;
  164.  
  165. int OP = 0;
  166. char OB[S];
  167.  
  168. inline char RC() {
  169.     static char buf[S], *p = buf, *q = buf;
  170.     return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
  171. }
  172.  
  173. inline int RI() {
  174.     static char c;
  175.     int a;
  176.     while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
  177.     if (c == '-') {
  178.         a = 0;
  179.         while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
  180.     }
  181.     else {
  182.         a = c ^ '0';
  183.         while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
  184.     }
  185.     return a;
  186. }
  187.  
  188. inline void WI(int n, char c = '\n') {
  189.     static char buf[20], p;
  190.     if (n == 0) OB[OP++] = '0';
  191.     p = 0;
  192.     if (n < 0) {
  193.         OB[OP++] = '-';
  194.         while (n) buf[p++] = '0' - (n % 10), n /= 10;
  195.     }
  196.     else {
  197.         while (n) buf[p++] = '0' + (n % 10), n /= 10;
  198.     }
  199.     for (--p; p >= 0; --p) OB[OP++] = buf[p];
  200.     OB[OP++] = c;
  201.     if (OP > S-20) write(1, OB, OP), OP = 0;
  202. }
  203.  
  204. /// Fast I/O by FHVirus ///
  205. /// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
  206. */
  207.  
Add Comment
Please, Sign In to add comment