Leetcode practice, you will always find that the code with short running times is similar:
Static int x=[] () { Std::ios::sync_with_stdio (false); Cin.tie (NULL); return 0 ;} ();
So I have a look at these lines of code:
Std::ios::sync_with_stdio (false);
This function is a "compatibility stdio" switch, C + + in order to be compatible with C, to ensure that the program in use of std::p rintf and std::cout without confusion, the output stream is tied together.
Cin,cout is inefficient because the first thing to output to buffer, and then output, resulting in reduced efficiency, and this statement can be used to eliminate iostream input and output cache , can save a lot of time, so that efficiency and scanf and printf, It should also be noted that the header files used by scanf and printf should be stdio.h instead of iostream.
Cin.tie (NULL);
The tie is a function that binds two stream, and the null argument returns the current output stream pointer
Reference article: https://www.cnblogs.com/PrayG/p/5749832.html
C + + input and output stream accelerator, turn off Sync stream, Ios::sync_with_stdio (false) and Cin.tie (0)