fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. static struct FastInput {
  4. static constexpr int BUF_SIZE = 1 << 20;
  5. char buf[BUF_SIZE];
  6. size_t chars_read = 0;
  7. size_t buf_pos = 0;
  8. FILE *in = stdin;
  9. char cur = 0;
  10.  
  11. inline char get_char() {
  12. if (buf_pos >= chars_read) {
  13. chars_read = fread(buf, 1, BUF_SIZE, in);
  14. buf_pos = 0;
  15. buf[0] = (chars_read == 0 ? -1 : buf[0]);
  16. }
  17. return cur = buf[buf_pos++];
  18. }
  19.  
  20. inline void tie(int) {}
  21.  
  22. inline explicit operator bool() {
  23. return cur != -1;
  24. }
  25.  
  26. inline static bool is_blank(char c) {
  27. return c <= ' ';
  28. }
  29.  
  30. inline bool skip_blanks() {
  31. while (is_blank(cur) && cur != -1) {
  32. get_char();
  33. }
  34. return cur != -1;
  35. }
  36.  
  37. inline FastInput& operator>>(char& c) {
  38. skip_blanks();
  39. c = cur;
  40. return *this;
  41. }
  42.  
  43. inline FastInput& operator>>(string& s) {
  44. if (skip_blanks()) {
  45. s.clear();
  46. do {
  47. s += cur;
  48. } while (!is_blank(get_char()));
  49. }
  50. return *this;
  51. }
  52.  
  53. template <typename T>
  54. inline FastInput& read_integer(T& n) {
  55. n = 0;
  56. if (skip_blanks()) {
  57. int sign = +1;
  58. if (cur == '-') {
  59. sign = -1;
  60. get_char();
  61. }
  62. do {
  63. n += n + (n << 3) + cur - '0';
  64. } while (!is_blank(get_char()));
  65. n *= sign;
  66. }
  67. return *this;
  68. }
  69.  
  70. template <typename T>
  71. inline typename enable_if<is_integral<T>::value, FastInput&>::type operator>>(T& n) {
  72. return read_integer(n);
  73. }
  74.  
  75. #if !defined(_WIN32) | defined(_WIN64)
  76. inline FastInput& operator>>(__int128& n) {
  77. return read_integer(n);
  78. }
  79. #endif
  80.  
  81. template <typename T>
  82. inline typename enable_if<is_floating_point<T>::value, FastInput&>::type operator>>(T& n) {
  83. n = 0;
  84. if (skip_blanks()) {
  85. string s;
  86. (*this) >> s;
  87. sscanf(s.c_str(), "%lf", &n);
  88. }
  89. return *this;
  90. }
  91. } fast_input;
  92. #define cin fast_input
  93.  
  94. static struct FastOutput {
  95. static constexpr int BUF_SIZE = 1 << 20;
  96. char buf[BUF_SIZE];
  97. size_t buf_pos = 0;
  98. static constexpr int TMP_SIZE = 1 << 20;
  99. char tmp[TMP_SIZE];
  100. FILE *out = stdout;
  101.  
  102. inline void put_char(char c) {
  103. buf[buf_pos++] = c;
  104. if (buf_pos == BUF_SIZE) {
  105. fwrite(buf, 1, buf_pos, out);
  106. buf_pos = 0;
  107. }
  108. }
  109.  
  110. ~FastOutput() {
  111. fwrite(buf, 1, buf_pos, out);
  112. }
  113.  
  114. inline FastOutput& operator<<(char c) {
  115. put_char(c);
  116. return *this;
  117. }
  118.  
  119. inline FastOutput& operator<<(const char* s) {
  120. while (*s) {
  121. put_char(*s++);
  122. }
  123. return *this;
  124. }
  125.  
  126. inline FastOutput& operator<<(const string& s) {
  127. for (int i = 0; i < (int) s.size(); i++) {
  128. put_char(s[i]);
  129. }
  130. return *this;
  131. }
  132.  
  133. template <typename T>
  134. inline char* integer_to_string(T n) {
  135. char* p = tmp + TMP_SIZE - 1;
  136. if (n == 0) {
  137. *--p = '0';
  138. } else {
  139. bool is_negative = false;
  140. if (n < 0) {
  141. is_negative = true;
  142. n = -n;
  143. }
  144. while (n > 0) {
  145. *--p = (char) ('0' + n % 10);
  146. n /= 10;
  147. }
  148. if (is_negative) {
  149. *--p = '-';
  150. }
  151. }
  152. return p;
  153. }
  154.  
  155. template <typename T>
  156. inline typename enable_if<is_integral<T>::value, char*>::type stringify(T n) {
  157. return integer_to_string(n);
  158. }
  159.  
  160. #if !defined(_WIN32) || defined(_WIN64)
  161. inline char* stringify(__int128 n) {
  162. return integer_to_string(n);
  163. }
  164. #endif
  165.  
  166. template <typename T>
  167. inline typename enable_if<is_floating_point<T>::value, char*>::type stringify(T n) {
  168. sprintf(tmp, "%.3f", n);
  169. return tmp;
  170. }
  171.  
  172. template <typename T>
  173. inline FastOutput& operator<<(const T& n) {
  174. auto p = stringify(n);
  175. for (; *p != 0; p++) {
  176. put_char(*p);
  177. }
  178. return *this;
  179. }
  180. } fast_output;
  181. #define cout fast_output
  182.  
  183. void solve(){
  184. cout << "These are fast input and output!";
  185. }
  186.  
  187. signed main(){
  188. ios_base::sync_with_stdio(false);
  189. if (fopen("main.inp","r")){
  190. freopen("main.inp","r",stdin);
  191. freopen("main.out","w",stdout);
  192. }
  193. int q = 1;
  194. if (!q) cin >> q;
  195. while (q--) solve();
  196. return 0 ^ 0;
  197. }
  198.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
These are fast input and output!