Here is the link of the problem : http://lightoj.com/volume_showproblem.php?problem=1135 link of code: https://ideone.com/h3Zu5C
Getting Runtime Error(RTE). Also in this problem: https://www.codechef.com/problems/MULTQ3
Can anyone help? Why getting RTE? Thanks in advance.
I can't open the lightoj problem but acc. to the codechef problem, you are not given the number of test cases. So, just removing that makes the program run successfully. ideone
it seems that the RTE is basically because of array accessing out of bounds
first silly mistake is
tree[Max*5]
, notice that#define MAX 100000+10
, so this is equivalent totree[100000+10*5]
which is 100050 which is not enough.yet, your code gives RTE you have to add a small condition in your
update_node()
function see this code herehowever, your code gives now TLE. revisit your code. i added a tiny optimization and it passed within 0.13 you can see the code here i added comments where the changes are made.
BTW, to locally test your program i think it's easier to use
while(scanf("%d %d",&n,&q) != EOF)
as in this way you don't have to comment anything before submittingfu**nny story, resubmitting the two above codes gives TLE sometimes and AC sometimes. i don't know what's wrong maybe it's because of the stupid judge :3 try submitting using c++14. i'm talking about CodeChef. both submissions seem fine with LightOJ.**
Thanks a lot! Finally getting AC in lightoj and codechef.