I came to spoj to practice questions on segment tree, first I solved “SEGSQRSS” got TLE, struggle and ask many good coders, everyone is saying the solution https://ideone.com/xsxZSw is perfect and good. Then I tried another problem “GSS1” same issue TLE https://ideone.com/JE4pQL. Then I translate the accepted solution of C++ into java then also same issue.
Why for java solution there is TLE. Everywhere my segment tree Java solution successfully submitter on Hackerearth, Codechef, etc. but not in spoj.