模板 - 數據結構 - 對頂堆
阿新 • • 發佈:2019-03-09
oid ott add greate hang otto tor pty val
#include<bits/stdc++.h> using namespace std; struct Opposite_Heap{ //top_heap has the min element,bottom heap has the max element priority_queue<int,vector<int>,less<int> > top_heap; priority_queue<int,vector<int>,greater<int> > bottom_heap;int k; Opposite(){k=0;} void add(int value){ /*change k*/ if(top_heap.size()<=i){ top_heap.push(value); } else{ if(value<top_heap.top()){ bottom_heap.push(top_heap.top()); top_heap.pop(); top_heap.push(value); }else{ bottom_heap.push(value); } } /*change k*/ } int get(){ /*change k*/ /*while(top_heap.size()<=k&&!bottom_heap.empty()){ top_heap.push(bottom_heap.top()); bottom_heap.pop(); }*/ intt=top_heap.top(); /*change k*/ while(top_heap.size()<=k&&!bottom_heap.empty()){ top_heap.push(bottom_heap.top()); bottom_heap.pop(); } return t; } };
模板 - 數據結構 - 對頂堆