PROBLEM LINK:MULTQ3 Problem - CodeChef

MY SUBMISSION LINK:CodeChef: Practical coding for everyone

My sample test cases are passing, and I have checked the use of long long everywhere, basically, I have created a segment tree that stores values with x%3==0,x%3==1, and x%3==2 but still not able to figure out what is exceeding the time limit???

Also tried to match my approach with others submission and they have also done the same thing as I and they are getting AC, but still not able to find where my code is giving TLE. Please help.

Just change the endl token at the end of line 124 to ā€˜\nā€™.

1 Like

thanks I did it ,but why did it happen ??Should I always use ā€œ\nā€??

endl does not only send ā€˜\nā€™ character, but it also flushes the output stream after that. You should always use cout << ā€˜\nā€™ when the number of queries is large, as the frequent output stream flushing degrades the performance due to its large overhead even when the output stream buffer has very few characters. The flushing operation is generally not necessary except in interactive problems.

1 Like

Check the following slight update to your solution of the problem.

1 Like

thank you