Skip to content

可删堆 ​

cpp
template<typename T>
struct Heap{
	// 可删堆,A-B
	priority_queue<T> A,B;
	void push(T x){
		A.push(x);
	}
	void erase(T x){
		B.push(x);
	}
	int top(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		return A.top();
	}
	int top2(){
		int t=top(),res;
		pop();
		res=top();
		A.push(t);
		return res;
	}
	void pop(){
		while(!B.empty()&&A.top()==B.top())A.pop(),B.pop();
		A.pop();
	}
};