跳到正文

题解

题解:AT_abc451_c [ABC451C] Understory

tddxs约 1 分钟
原文

这是 2026年3月31日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年3月31日
收录
2026年3月31日
更新
2026年11月15日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

题目中要求在每个2操作删除最小的一些元素,因此考虑使用小根堆来维护。

具体地,在每个1操作直接将 hh 放入堆中,在每个2操作不断删除堆顶元素直到堆顶元素超过 hh 为止。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
int Q,op,h;
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>Q;
	while(Q--){
		cin>>op>>h;
		if(op==1){
			q.push(h); 
		}
		if(op==2){
			if(q.size()){
				while(q.top()<=h){
					q.pop();
					if(q.empty())break;
				}
			}
		}
		cout<<q.size()<<'\n';
	}
	return 0;
}