Here is my submission. I have added comments explaining every step.
I think there exists a much simpler solution using last and previous indices,2 segment trees and offline processing:
Edit : Segment trees are Min. Max. segment trees
do you have any resource so that i can get to know about MO’s algo
plz help
this is my submission
my approach is almost similar to u
but i m getting tle
can u plz tell me why it is getting tle
Finally, I was able to write the AC code with this approach Here.
It took me a lot of debugging, but it was a good problem for implementation.
I’ve walked through the code @mkitkat . But still I’m getting TLE for my Mo’s solution.
Can you have a look and lemme know of any optimisation which can help reduce the time further Submission (41325957) for Happy segments | HackerEarth
Can you elaborate what last and previous are here? And please brief about what approach you used?
What are doing in loop starting at line 164 in your code?