采集求助
查看原帖
采集求助
160839
Prean楼主2020/8/9 19:27

类似ODT的思想都写不对,我是不是该退役了。。。

code:

#include<cstdio>
#include<set>
struct Node{
    int L,R;
    Node(int L=0,int R=0):L(L),R(R){}
    inline bool operator<(const Node&a)const{
        return L<a.L;
    }
};
std::set<Node>ODT;
std::set<Node>::iterator now,end;
signed main(){
    int n,L,R;char s;
    scanf("%d",&n);
    while(n--){
        getchar();
        scanf("%c",&s);
        if(s==65){
            int ans=0;
            scanf("%d%d",&L,&R);
            now=ODT.lower_bound(Node(L));
            end=ODT.lower_bound(Node(R+1));
            while(now!=end){
                ++ans;ODT.erase(now++);
            }
            if(end!=ODT.end()&&end->R>=L)ODT.erase(end),++ans;
            ODT.insert(Node(L,R));
            printf("%d\n",ans);
        }
        if(s==66){
            printf("%d\n",ODT.size());
        }
    }
}
2020/8/9 19:27
加载中...