log(n) version of copy