zoukankan      html  css  js  c++  java
  • [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;
        
    }
  • 相关阅读:
    iOS7 自己定义动画跳转
    Android开发之用双缓冲技术绘图
    postgres 使用存储过程批量插入数据
    渗透过程
    python pytesseract使用
    排序算法比较
    python算法
    python中PIL模块
    数字电路复习
    windows服务参考
  • 原文地址:https://www.cnblogs.com/evenbao/p/9902314.html
Copyright © 2011-2022 走看看