What is this about?

I found this interesting problem on hackerearth but unfortunately I couldn’t find any optimal solution to this.

Please look into this : Log In | HackerEarth

Greetings.

You can solve this using Seg tree by iterating from i = n till i = 1 and at every index calculating element with highest index that has value less than a[i] , however , you also have to apply coordinate compression as 1<= a[i] <= 1e9 ( can be implemented using ordered_set)
The solution : top_speed - Pastebin.com
I am not sure if this is the perfect answer , but it gives rough idea of what I am thinking

This solution isn’t working however I am now clear about the data structure. :sweat_smile:

I will definitely go through ordered_set approach.