fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. template<typename T>
  5. int SIZE(T (&t)){
  6. return t.size();
  7. }
  8.  
  9. template<typename T, size_t N>
  10. int SIZE(T (&t)[N]){
  11. return N;
  12. }
  13.  
  14. string to_string(char t){
  15. return "'" + string({t}) + "'";
  16. }
  17.  
  18. string to_string(bool t){
  19. return t ? "true" : "false";
  20. }
  21.  
  22. string to_string(const string &t, int x1=0, int x2=1e9){
  23. string ret = "";
  24. for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){
  25. ret += t[i];
  26. }
  27. return '"' + ret + '"';
  28. }
  29.  
  30. string to_string(const char* t){
  31. string ret(t);
  32. return to_string(ret);
  33. }
  34.  
  35. template<size_t N>
  36. string to_string(const bitset<N> &t, int x1=0, int x2=1e9){
  37. string ret = "";
  38. for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){
  39. ret += t[i] + '0';
  40. }
  41. return to_string(ret);
  42. }
  43.  
  44. template<typename T, typename... Coords>
  45. string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C);
  46.  
  47. template<typename T, typename S>
  48. string to_string(const pair<T, S> &t){
  49. return "(" + to_string(t.first) + ", " + to_string(t.second) + ")";
  50. }
  51.  
  52. template<typename T, typename... Coords>
  53. string to_string(const T (&t), int x1, int x2, Coords... C){
  54. string ret = "[";
  55. x1 = min(x1, SIZE(t));
  56. auto e = begin(t);
  57. advance(e,x1);
  58. for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){
  59. ret += to_string(*e, C...) + (i != _i ? ", " : "");
  60. e = next(e);
  61. }
  62. return ret + "]";
  63. }
  64.  
  65. template<int Index, typename... Ts>
  66. struct print_tuple{
  67. string operator() (const tuple<Ts...>& t) {
  68. string ret = print_tuple<Index - 1, Ts...>{}(t);
  69. ret += (Index ? ", " : "");
  70. return ret + to_string(get<Index>(t));
  71. }
  72. };
  73.  
  74. template<typename... Ts>
  75. struct print_tuple<0, Ts...> {
  76. string operator() (const tuple<Ts...>& t) {
  77. return to_string(get<0>(t));
  78. }
  79. };
  80.  
  81. template<typename... Ts>
  82. string to_string(const tuple<Ts...>& t) {
  83. const auto Size = tuple_size<tuple<Ts...>>::value;
  84. return print_tuple<Size - 1, Ts...>{}(t);
  85. }
  86.  
  87. void dbgr(){;}
  88. template<typename Heads, typename... Tails>
  89. void dbgr(Heads H, Tails... T){
  90. cout << to_string(H) << " | ";
  91. dbgr(T...);
  92. }
  93.  
  94. void dbgs(){;}
  95. template<typename Heads, typename... Tails>
  96. void dbgs(Heads H, Tails... T){
  97. cout << H << " ";
  98. dbgs(T...);
  99. }
  100.  
  101. /*
  102. formatted functions:
  103. */
  104.  
  105. /*
  106. consider __VA_ARGS__ as a whole:
  107. dbgv() prints values only
  108. dbg() prints name and values
  109. */
  110. #define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
  111.  
  112. #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
  113.  
  114. /*
  115. consider __VA_ARGS__ as a sequence of arguments:
  116. dbgr() prints values only
  117. dbgm() prints names and values
  118. */
  119. #define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
  120.  
  121. #define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
  122.  
  123. /*
  124. dbgs() prints only values separated by spaces
  125. */
  126.  
  127. /*
  128. compact version
  129. template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); }
  130. #define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
  131. #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
  132. #define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
  133. #define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
  134. */
  135.  
  136. int main(){
  137.  
  138. /*...useful defines...*/
  139. #define fou(i,a,b) for(int i = a, _i = b; i <= _i; ++i)
  140. #define fod(i,a,b) for(int i = a, _i = b; i >= _i; --i)
  141.  
  142. /*...tests...*/
  143.  
  144. int j[2][2][3] = {{{4,5,6},{10,11,12}}, {{1,2,3}, {7,8,9}}};
  145. dbg(j);
  146. dbg(j,0,0,0,1,0,1);
  147.  
  148. fou(x,0,0) fou(y,0,1) dbgv(j[x][y]);
  149.  
  150.  
  151. map<vector<int>, vector<string>> a = {{{3,4},{"sauron"}}, {{1,2},{"gandalf", "the", "grey"}}, {{5},{"frodo","bilbo"}}};
  152. dbg(a);
  153. dbg(a,0,1);
  154. dbg(a,5,5);
  155.  
  156.  
  157. set<vector<string>> b[3] = {{{"abc", "def"},{"ghi"}}, {{"klm","nop"},{"qrs"}}, {{"tuv", "wxy", "zab"}}};
  158. dbg(b,1,2,0,0,0,0,1,2);
  159. dbg(b,1,2,0,0,0,0);
  160. dbg(b,1,2,0,0);
  161. dbg(b,1,2);
  162. dbg(b);
  163.  
  164. fou(i,0,2) dbgv(b[i]);
  165.  
  166. map<int, map<int,int>> c = {{1,{{2,3}}},{4,{{5,6},{7,8}}},{9,{{10,11}}}};
  167. dbg(c,0,0);
  168. dbg(c);
  169.  
  170.  
  171. vector<bitset<10>> q = {{12},{13},{14},{15}};
  172. dbg(q);
  173. dbg(q,1,2,0,2);
  174. dbg(q,5,5,0,2);
  175.  
  176. for(int i = 0; i < 2; ++i) {
  177. dbgm(q[i]);
  178. }
  179.  
  180. pair<int, set<int>> m = {1, {2,3,3,3,4}};
  181. dbg(m);
  182.  
  183.  
  184. deque<int> i = {9,10,11,12};
  185. dbg(i);
  186. dbg(i,2,3);
  187.  
  188.  
  189. set<pair<int, int>> x{{1,2},{3,4}};
  190. dbg(x,1,1);
  191. dbg(x);
  192.  
  193.  
  194. string s = {"codeforces"};
  195. dbg(s,20,1);
  196. dbg(s,1,4);
  197.  
  198.  
  199. int t = 5; char u = 'R';
  200. pair<pair<double, unsigned int>, pair<int, string>> v = {{234.34534, 42}, {133, "IOI"}};
  201.  
  202. dbgm(s,t,u,v);
  203.  
  204. dbgm(5.345,7,12);
  205.  
  206. struct S {int a, b; pair<int, bitset<4>> c; vector<int> d;} w{2,3,{5,6},{7,1,6,3,7}};
  207. auto W = make_tuple(w.a, w.b, w.c, w.d);
  208.  
  209. dbg(W);
  210.  
  211. dbgm(w.a, w.b, w.c, w.d);
  212.  
  213. dbgs(4, "$", '^'); cout << endl;
  214.  
  215. dbgr(5, bitset<4>(2), vector<int>({4,5,2,8}));
  216. }
Success #stdin #stdout 0s 15296KB
stdin
Standard input is empty
stdout
[j]: [[[4, 5, 6], [10, 11, 12]], [[1, 2, 3], [7, 8, 9]]]
[j,0,0,0,1,0,1]: [[[4, 5], [10, 11]]]
[4, 5, 6]
[10, 11, 12]
[a]: [([1, 2], ["gandalf", "the", "grey"]), ([3, 4], ["sauron"]), ([5], ["frodo", "bilbo"])]
[a,0,1]: [([1, 2], ["gandalf", "the", "grey"]), ([3, 4], ["sauron"])]
[a,5,5]: []
[b,1,2,0,0,0,0,1,2]: [[["lm"]], [["uv"]]]
[b,1,2,0,0,0,0]: [[["klm"]], [["tuv"]]]
[b,1,2,0,0]: [[["klm", "nop"]], [["tuv", "wxy", "zab"]]]
[b,1,2]: [[["klm", "nop"], ["qrs"]], [["tuv", "wxy", "zab"]]]
[b]: [[["abc", "def"], ["ghi"]], [["klm", "nop"], ["qrs"]], [["tuv", "wxy", "zab"]]]
[["abc", "def"], ["ghi"]]
[["klm", "nop"], ["qrs"]]
[["tuv", "wxy", "zab"]]
[c,0,0]: [(1, [(2, 3)])]
[c]: [(1, [(2, 3)]), (4, [(5, 6), (7, 8)]), (9, [(10, 11)])]
[q]: ["0011000000", "1011000000", "0111000000", "1111000000"]
[q,1,2,0,2]: ["101", "011"]
[q,5,5,0,2]: []
[q[i]]: "0011000000" | 
[q[i]]: "1011000000" | 
[m]: (1, [2, 3, 4])
[i]: [9, 10, 11, 12]
[i,2,3]: [11, 12]
[x,1,1]: [(3, 4)]
[x]: [(1, 2), (3, 4)]
[s,20,1]: ""
[s,1,4]: "odef"
[s,t,u,v]: "codeforces" | 5 | 'R' | ((234.345340, 42), (133, "IOI")) | 
[5.345,7,12]: 5.345000 | 7 | 12 | 
[W]: 2, 3, (5, "0110"), [7, 1, 6, 3, 7]
[w.a, w.b, w.c, w.d]: 2 | 3 | (5, "0110") | [7, 1, 6, 3, 7] | 
4 $ ^ 
5 | "0100" | [4, 5, 2, 8] |