priority_queue "C++ reference"上如此解释priority queue:"This context is similar to a heap, where elements can be inserted at any moment, and only the max heap element can be retrieved (the one at the top in the priority queue)." 这里用个小例子使用下p
1. Top k 大的数 排序后直接索引输出:O(nlogn)" role="presentation">O(nlogn)O(nlogn) std::sort(v.rbegin(), r.rend()); return v[k-1]; 使用优先队列(O(klogn)" role="presentation">O(klogn)O(klogn),每 pop 一个元素,都需重排大顶堆): std::priority_queue<