I’ve recently come across the following three types of fast IO:
ios_base::sync_with_stdio(0); cin.tie(0); (probably the most common)
cin.tie(0)->sync_with_stdio(0); (I use this because it feels cool to type)
cin.sync_with_stdio(0); (Polish problemsetters use this sometimes)
My understanding is that
ios_base::sync_with_stdio(0) disables synchronization between C and C++ standard streams (i.e.
What’s the difference between the three types above? If there is a speed difference, is it significant?
cin.sync_with_stdio(0); is the same as
ios_base::sync_with_stdio(0); (you can check w/ https://godbolt.org/)
Also from http://www.cplusplus.com/reference/ios/ios_base/sync_with_stdio/:
Notice that this is a static member function, and a call to this function using this member of any stream object toggles on or off synchronization for all standard iostream objects.
So the first two are essentially equivalent aside from calling the functions in different orders. Last one doesn’t have
tie, not sure how significant the speed difference is.
I asked around and apparently not having
cin.tie(0) is basically just like using
endl, so it only really matters in query problems