关于ios::sync_with_stdio(false);

 ios::sync_with_stdio(false); 

ios_base::sync_with_stdio - C++ Reference (cplusplus.com)

优点是提高 cin>> 的读取速度,缺点是不能再使用 scanf() 

输入规模≥一百万,建议使用 scanf() ——yxc

 关于ios::sync_with_stdio(false);和 cin.tie(nullptr);_Canger_的博客-CSDN博客

iostream默认是与stdio关联在一起的,以使两者同步,因此消耗了iostream不少性能。C++中的std :: cin和std :: cout为了兼容C,保证在代码中同时出现std :: cin和scanf或std :: cout和printf时输出不发生混乱,所以C++用一个流缓冲区来同步C的标准流。通过std :: ios_base :: sync_with_stdio函数设置为false后可以解除这种同步,让std :: cin和std :: cout不再经过缓冲区,iostream的性能就会提高了很多倍。因此,当解除同步之后,注意不要与scanf和printf混用以免出现问题。
————————————————
版权声明:本文为CSDN博主「canger_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Canger_/article/details/85787436

原文地址:https://www.cnblogs.com/infocodez/p/15021748.html