Issue with SUBPRNJL

I have been trying to solve this question using maps and sets, and generating the subarrays using the recursive approach but still getting a TLE… Any suggestions…?

https://www.codechef.com/viewsolution/33118204