How does a treap help to update this ordered queue?
问题 I'm having trouble understanding this solution to a problem on HackerRank. Please see the solution code below, apparently by Kimiyuki Onaka. The problem is: given a list of unique numbers, and m queries of the type, " move the current ith to jth elements (l,r) to the beginning ", return the final arrangement of the numbers. Onaka suggests that a treap data structure (one that maintains both priority and binary search) can help solve it in O(m log n) . Since I'm not versed in C++, I've tried