reduce the running time to O(nlogn), but not fast enough.