|BZOJ 2028|平衡树|[SHOI2009]会场预约

BZOJ传送门
luogu免权限地址
Set求大于x的最小值的模板题。注意set.lower_bound()如果找不到就会返回set.end()

#include<cstdio>    
#include<algorithm>    
#include<cstring>     
#include<set>   
#define ms(i,j) memset(i,j, sizeof i);    
using namespace std; 
int n; 
struct qj 
{
    int l, r;
    bool operator <(const qj &b) const
    {
        if (r<b.r) return true;
        if (r>b.r) return false;
        return l<b.l;
    }
};
set<qj> s; 
char inpu()
{
    char ans = getchar();
    while ((ans!='A')&&(ans!='B')) 
    ans = getchar();
    return ans;
}
int main()   
{     
    scanf("%d", &n);
    for (int i=1;i<=n;i++)
    {
        char type = inpu();
        if (type=='A')
        {
            int cnt = 0; 
            int l,r;
            scanf("%d%d", &l, &r);
            qj a = (qj){l,r};
            while (true)
            {
                set<qj>::iterator it = s.lower_bound((qj){0,l});//找第一个比a大的qj 
                int xl = it->l, xr = it->r;
                if (it!=s.end())//set里还有元素 
                {
                    if (!(a.r < it->l))//有覆盖 
                    {
                        s.erase(it);
                        cnt++;
                        continue;
                    }
                }
                s.insert(a); 
                break;
            }
            printf("%d\n", cnt);
        } else printf("%d\n", s.size());
    }
    return 0;    
}    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值