ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1126. Magnetic Storms

TL on test 2; O( (n-m)*log m ), is O(n logm) slow ?
Posted by cs_Diablo 1 Oct 2011 22:49
I'm calculating for every interval the max element with binary indexed tree in log(n) time. But still got TL on test 2. Is it ok NlogM to be slow ?
Re: TL on test 2; O( (n-m)*log m ), is O(n logm) slow ?
Posted by Noob 2 Oct 2011 00:18
It can be solved in O(NM), TLE is too big. Once my friend did it :)
I think there's a bug in your implementation.
Re: TL on test 2; O( (n-m)*log m ), is O(n logm) slow ?
Posted by MOPDOBOPOT (USU) 31 Jul 2012 21:06
Are you sure that (build a tree on i-th step) + (find element) works in O(NlogM)?
I used two stacks (they works like queue) with access to max element in O(1) (something like 3 operations on each element). So it can be solved in O(n)!