[SHOI 2009] 会场预约

Posted evenbao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[SHOI 2009] 会场预约相关的知识,希望对你有一定的参考价值。

[题目链接]

       https://www.lydsy.com/JudgeOnline/problem.php?id=2028

[算法]

        直接用std :: set维护即可 

        时间复杂度 : O(NlogN)

[代码]

       

#include<bits/stdc++.h>
using namespace std;

int n;

struct segment
{
        int l , r;
        friend bool operator < (segment a , segment b)
        {
                if (a.r == b.r) return a.l < b.l;
                else return a.r < b.r;
        }
} ;

template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == -) f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - 0;
    x *= f;
}
int main()
{
        
        scanf("%d" , &n);
        set< segment > S;
        for (int i = 1; i <= n; i++)
        {
                char type[5];
                scanf("%s" , &type);
                if (type[0] == B)
                {
                        printf("%d
" , (int)S.size());
                        continue;
                } else
                {
                        int ans = 0;
                        int l , r;
                        scanf("%d%d" , &l , &r);
                        while (true)
                        {
                                set< segment > :: iterator it = S.lower_bound((segment){0 , l}); 
                                if (it == S.end()) break;
                                segment tmp = (*it);
                                if (tmp.l <= r)
                                {
                                        S.erase(it);
                                        ++ans;        
                                } else break;
                        }
                        printf("%d
" , ans);
                        S.insert((segment){l , r});
                }
        }
        
        return 0;
    
}

 

以上是关于[SHOI 2009] 会场预约的主要内容,如果未能解决你的问题,请参考以下文章

[SHOI2009]会场预约

SHOI 2009 会场预约 平衡树 STL练习

LuoguP2161 [SHOI2009]会场预约

P2161 [SHOI2009]会场预约

P2161 [SHOI2009]会场预约 - 线段树染色

[LuoguP2161[ [SHOI2009]会场预约 (splay)