Блог пользователя alexmcmahon

Автор alexmcmahon, история, 6 месяцев назад, По-английски

Hello, Codeforces!

I'm excited to share my C++ library that can significantly improve the performance of your solutions, especially when dealing with large input and output.

https://github.com/emeraldacoustics/fast-io

Example

For years, I've been using this library myself, and it consistently delivers:

  • 5x faster I/O on average: Solve problems quicker and avoid unnecessary timeouts.

  • Blazing-fast performance for large data: Notice a 10x speedup for inputs/outputs exceeding 1MB.

But speed isn't everything! This library also prioritizes ease of use:

  • Seamless integration: Simply replace cin and cout with fin and fout in your code.

  • Familiar syntax: The library implements standard C++ stream operators for an intuitive experience.

  • Extended Compatibility: Handles all fundamental data types and offers precision control for floating-point numbers.

I'm confident this library can be a valuable asset for you, especially when dealing with large data. While this is just the first step, stay tuned for future posts where I'll introduce more tools and techniques to help you conquer Codeforces!

Thank you.

  • Проголосовать: нравится
  • +33
  • Проголосовать: не нравится

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by alexmcmahon (previous revision, new revision, compare).

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by alexmcmahon (previous revision, new revision, compare).

»
6 месяцев назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

Wow, this library is wonderful!

This is the most easy-to-use fast I/O library I've ever seen. Replacing cin and cout was a breeze.

I also love your recent repositories. Are you still working on them?

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Thanks. I've been working on new competitive algorithm repos. I'll post them as soon as I finish the documentation.

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Does this work for interactive problems?

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    To be honest, no. Besides, interactive problems typically involve smaller data exchanges for communication with the judge

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I saw your repository and would you mind telling how were you able to achieve those optimizations. Great work btw

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Great work!!

»
6 месяцев назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

did u do any comparison with the ios default fastIO:
cin.tie(0)->sync_with_stdio(0)??

»
6 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

It's quite useful, but its total size reaches 11.6 KB. Completely pasting it in our code will significantly increase our code size. Could you please compress your code a bit? alexmcmahon

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks for your kind suggestion. I agree with the idea that the code size is quite humongous, and using stringstream to resolve the issue is being considered.

»
6 месяцев назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

please let me know how to use it!!

  • »
    »
    6 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Oh, my pleasure. Copy fiostream_x86.hpp source into your solution. If you need to input or output 128-bit integers, use fiostream_x64.hpp.

    Replace cin with fin, cout with fout, and endl with fendl.

    When you are testing fast-io via standard input and output, don't forget to input a null character at the end of your input, i.e., Ctrl+Z in Windows.

    • »
      »
      »
      5 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Sorry I am new to computer stuff, when I have to use long long/long long int/long double, I need to use fiostream_x64.hpp, for int/double fiostream_x86.hpp is ok. Is my understanding correct?

      • »
        »
        »
        »
        5 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I'm afraid not. fiostream_x86.hpp works for long long and long double. But you must choose fiostream_x64.hpp if 128-bit integers have to be input or output.

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Why are we downvoting the comments again?

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I have no idea why they're downvoting this blog and its comments without any reason. I think this Fast I/O would give us a big help, and that no one would downvote it. I wanna know what the downvoters think. Why don't they just express their ideas about this blog?

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Have you tested it rigorously? In other words, can we be 100% confident that your program is correct? :)

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yes, I have. My friends and I have tested this library for over 5 years, which has given us high confidence in its ability to handle a wide range of exceptions. This library has proven its reliability and efficiency on various CP platforms. I assure you that this library works correctly and provides the same behavior as the standard I/O streams.

    • »
      »
      »
      6 месяцев назад, # ^ |
      Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

      Library is 5 years old and using namespaces std; is still there in header files? :)

      If you wrote custom stream buffers instead, everyone would be able to use them with other streams too.

      BTW, I wrote simple test program, ran it and got segmentation fault in fistream::next_buffer(). Maybe I did something wrong but let us consider the following program:

      #include <iostream>
      #include <string>
      
      int main()
      {
          std::cout << "Enter name: ";
      
          std::string name;
          std::cin >> name;
      
          return 0;
      }
      

      After replacement std::cout with fout and std::cin with fin we have this one:

      #include "fiostream_x86.hpp"
      #include <string>
      
      int main()
      {
          fout << "Enter name: ";
      
          std::string name;
          fin >> name;
      
          return 0;
      }
      

      But it does not even compile:

      fiostream_test.cpp:10:9: error: no match for ‘operator>>’ (operand types are ‘fistream’ and ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’})
      
      • »
        »
        »
        »
        6 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Please have a look at fistream and fostream declaration. I'm afraid this library doesn't support input and output for std::string.

        fistream & operator >> (char &);
        fistream & operator >> (char *);
        fistream & operator >> (int &);
        fistream & operator >> (unsigned int &);
        fistream & operator >> (long long &);
        fistream & operator >> (unsigned long long &);
        fistream & operator >> (__int128 &);
        fistream & operator >> (unsigned __int128 &);
        fistream & operator >> (float &);
        fistream & operator >> (double &);
        fistream & operator >> (long double &);
        

        Thanks for your comment and I'll keep that in mind in updating my library.

»
6 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

I didn't know there were other competitive programmers in Ireland

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

main.cpp:1:10: fatal error: fiostream_x86.h: No such file or directory 1 | #include "fiostream_x86.h" | ^~~~~~~~~~~~~~~~~ compilation terminated.

»
5 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

eXXXXXXXXXXXXXXXXXXcellent work!

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

does this library use any x86 specific instruction ?? cause the files in the repo were named using it!

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Maybe I'm just stupid/ignorant at this point, but could anyone tell me how to use custom libraries in online judges in a reasonable way?

  • »
    »
    5 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Instead of including the custom libraries in the header, you can copy them into your source code if you want to use them for online judges.

»
3 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Nice. I have always wondered. How does one go about learning enough C++ to be able to code something like this?