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 : https://www.hackerearth.com/challenges/hiring/traveloka-intern-hiring-challenge-2019/algorithm/top-speed-de8a7558/description/


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 : https://pastebin.com/CqVU67xD
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.