spoj subarray problem

I have been trying this subarray problem on spoj for a while and used a segtree in my approach but it is giving tle. It passes all tc given in comments below but gives tle on submission. can someone help me identify my mistake.question link mycode it would be really helpful if someone can help me

We cant see your code,better provide some ideone link or something…

And u can simply use maps,to solve this,i mean lets say for [1:k] your map will contain arr[1] to arr[k],find maximum using map,then for range[2:k+1],remove arr[1] ,add arr[k+1] to map

see this:


1 Like

actually i went through your code, and it seems a great way to solve the problem, but i just edited the link, can u tell me why my seg tree code gives tle.

Same old fashioned optimisations,’\n’ instead of endl,fast io,instead of a*2->(a<<1),instead of a/2->(a>>1),int instead of long long