11235 - Frequent values
Posted: Sat Jul 07, 2007 8:08 pm
I tried so many inputs and all of them seems to be right. but i am having WA.
can anybody give some tricky test cases
thanks
can anybody give some tricky test cases
thanks
Code: Select all
7 1
1 2 2 2 2 2 3
3 5
0
Think about Range Maximum Query(RMQ), then you can answer each query in O(lg N) operation after O(N lg N) for build the tree. You must transform the problem to RMQ first ^_^.898989 wrote:Hi
Can any one describe efficient algorithm for the problem that will pass the system tests.
I can't think of anything other than a simple O(nlogn) solution, and even my modest solution takes around 4 secs.sohel wrote:A clever bruteforce is also enough to pass the time limit.
O(n log n) preprocessing -> O(log n) query answering? If you use binary trees, I think the preprocessing part is O(n) not O(n log n). The tree you construct has: n + n/2 + n/4 + ... nodes, which sum to 2n, not n log n.Timo wrote:Think about Range Maximum Query(RMQ), then you can answer each query in O(lg N) operation after O(N lg N) for build the tree. You must transform the problem to RMQ first ^_^.
My tree was a bit different ^_^, so the reconstruction will need O(n lg n).Hadi wrote:O(n log n) preprocessing -> O(log n) query answering? If you use binary trees, I think the preprocessing part is O(n) not O(n log n). The tree you construct has: n + n/2 + n/4 + ... nodes, which sum to 2n, not n log n.Timo wrote:Think about Range Maximum Query(RMQ), then you can answer each query in O(lg N) operation after O(N lg N) for build the tree. You must transform the problem to RMQ first ^_^.
The solution I used during the contest: O(n log n) preprocessing -> O(1) query answering.
Can you tell about your solution?Hadi wrote: The solution I used during the contest: O(n log n) preprocessing -> O(1) query answering.