In problem 220B - Little Elephant and Array my submission 36377029 got WA. Then I comment ios_base::sync_with_stdio(0) and submit the same code 36377330 again. It got accepted. Now I wonder why my first code got WA and when we should use ios_base::sync_with_stdio(0) and when we shouldn't.
I think you only use it if you are using cin and cout. Don't mix cin/scanf/cout/printf or weird things can happen.
I submitted this 36376045 with ios_base::sync_with_stdio(0) , cin and cout. No scanf, printf. But it got TLE. And in this 36378988 submission I add cout.tie(0) with them. But
it got WA. :(
On your second sumbission you forget to delete scanf and printf, that's why you got WA.
Thanks. cin.tie(0) works 36386259.
But still wonder why ios_base::sync_with_stdio(0) without cin.tie(0) gives WA in this problem.
I would also add that this optimisation only makes sense if your input or output have more than a constant amount of characters (e.g. if there is a valid test in which any of these reach at least a thousand), because otherwise the time you spend on executing this function overweights the time you save from input/output.
You can also use cin.tie(0) and cout.tie(0) in addition to this, they as well speed things up a bit.