AT_abc451_c 题解
NoneOfTheAbove · · 题解
luogu link
AT link
Solution
按照题意,用 multiset 维护树,直接模拟就能过了,删除就是先找到第一个比
因为最多就加进来
Code
:::success[code]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef double db;
typedef __int128 i128;
const ll inf=9e18;
const i128 Inf=1e35;
multiset<ll> ms;
ll q,id,h;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>q;
while(q--)
{
cin>>id>>h;
if(id==1) ms.insert(h); //加入一棵高度为 h 的树
else
{
auto it=ms.upper_bound(h);//找到第一棵高度大于 h 的树
ms.erase(ms.begin(),it);//把比它小的树全删了
}
cout<<ms.size()<<'\n';//剩下树的个数
}
}
:::