I am trying to solve this treap problem. http://poj.org/problem?id=3580 But it is getting TLE, though I think my solution is O(nlogn). If the code is poorly written how can I optimize it? Thanks for your help. Here is my code: http://paste.ubuntu.com/8533067/ Update: I got accepted by using an overloaded new operator(allocated 40mb at first). Here is accepted code: http://paste.ubuntu.com/8539750/
Maybe if node objects will be close in memory, it'll be faster. I would try to allocate treap nodes in one array.
Well I just submitted my code with an overloaded new operator as you said. And got accepted. Thanks.