Earlier i coded it using normal segment trees approach,and i was getting tle ,so i used lazy technique,now i am getting wrong answer.
What is the problem with following code?
No there will be many updates(range update of length k) for each update as given array elemnt is updated and each node of segment tree stores atleast sum of k terms of given array.Each leaf node is storing a term of F(x,k).
In my approach.I hope you got my approach what i am doing.
@chhabrapiyush480
Use fast IO.
Your segment tree code is not correct. While you are pushing down updates you need to check if s!=e.
hi arnav jindal,if u see carefully i have declared size of lazy array as 9*n,so updating even the lazy value for leaf node’s children will not affect my solution,and that’s what i am doing.
@chhabrapiyush480
Not all leafs are at same level. It might happen that you update lazy value for leaf and end up wrongly modifying a node in the data which is important to us.
Please make the required change and run the code once.
I did what you said but no benefit.
@chhabrapiyush480
I’ve modified your code and made it simpler. It is working now. Please see this https://ide.codingblocks.com/s/193440.
If your doubt is resolved please mark it as closed.
But i still cant get what was problem in my code,although this(your) approach is much easier and better.But i was also doing almost same thing.
@chhabrapiyush480
I agree with you. Basic approach is the same. But due to complexity we may be missing something trivial and incorrect in your implementation.
In such cases I generally see the correct approach and move on and would suggest you to do the same than trying to find a minute error that might not be visible right now.
Yes you are absolutely right,i also move on,but this has happened to around 5-6 questions in last 3-4 days ,where neither me nor TA is able to find bug in my code,how unlucky it is for me ,i write almost correct code but it doesnt work.
Thanks for the help btw.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.