use avl tree for fast nth