problem:- link text
my solution:-link text
Why im getting TLE error,I think my logic is right. Now how can i optimise my solution.Plz explain me
problem:- link text
my solution:-link text
Why im getting TLE error,I think my logic is right. Now how can i optimise my solution.Plz explain me
Your solution seems correct to me, but I don’t think your approach is good enough for given constraint.I think, it’s a BIT-related problem.You have to think according to that.
Here is a good tutorial to get started with BIT.
Happy Coding!
Only those who solved the problem can see your solution atm. Try to give the ideone link for others.
for(i=temp;i<n-count;i++)
a[i]=a[i+1];
This shifting of array elements is bound to give you TLE. It makes complexity roughly O(NQ).
This problem needs you to use apt data structure. Check ayushagg31 's answer. You need Binary Indexed Tree for this problem.