跳到正文

题解

AT_abc451_c 题解

NoneOfTheAbove约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年3月28日
收录
2026年4月27日
更新
2026年9月20日
篇幅
约 2 分钟

版本

  1. v1当前

luogu link

AT link

Solution

按照题意,用 multiset 维护树,直接模拟就能过了,删除就是先找到第一个比 hh 大的数,然后把前面的全删了。

因为最多就加进来 qq 个,时间复杂度是 O(qlog⁡q)O(q \log q),可以过。

Code

code
C++
#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';//剩下树的个数
    }
}
原文