Problem Link - http://www.spoj.com/problems/RPLN/
Ideone Link for code - http://ideone.com/hvZSi9
I have used Segment tree method to solve this.Please help me in figuring out what’s wrong with this code.
THANKS IN ADVANCE
Problem Link - http://www.spoj.com/problems/RPLN/
Ideone Link for code - http://ideone.com/hvZSi9
I have used Segment tree method to solve this.Please help me in figuring out what’s wrong with this code.
THANKS IN ADVANCE
Instead of using cout and cin use printf() and scanf().
You dont have to initialise the tree with zero for every test case.
I think this should do.
done , still getting TLE. Thanks for helping though
still need help?
Your code get ac when submitted by removing all the "endl"s
in general, avoid using endls, instead use ‘\n’.
but if you still want your endls, just include this line on top of your code->
" #define endl ‘\n’ "
if this helped, it would be great if you could upvote this answer…
It helped me get the AC thanks for that.
But , I was actually looking for corrections in approach.Anyways , thanks for the help though.
You will get an upvote for this buddy
@shubham99, the reason is using endl flushes the output stream after printing new line. Hence its slower where’s otherwise all data is stored in a buffer and whole buffer is printed at once. Link: http://www.cplusplus.com/reference/ostream/ostream/flush/
Thanks @vsp4 , I have seen that link after looking at that answer although thanks for pointing it out. Actually , I am looking for the optimizations to make my program faster if possible by some small corrections missed by me.
i don’t think that you would be able to make this Segtree any faster. All the operations are perfect. Also, why not use vectors? http://stackoverflow.com/questions/381621/using-arrays-or-stdvectors-in-c-whats-the-performance-gap