SHOI2009 venue reservation

Topic Portal

Ah, This question tag is STL , because the STL with a really really wonderful


This question is required to maintain a bunch of intervals, and an important operation is to remove all of the new interval conflict zone

Though it is possible \ (Splay \) to operate, but with the STL is set definitely not imaginary
wherein undoubtedly the most sophisticated operator overloading
It means that when the intersection of two sections, both sections are equal

struct zzz {
    int l, r;
    bool operator < (const zzz &y) const { return r < y.l; }
}; set <zzz> q;

End overloaded operators, set again with the find function, can easily by this question

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define LL long long
using namespace std;
LL read() {
    LL k = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9')
        k = k * 10 + c - 48, c= getchar();
    return k;
}
char read_c() {
    char c = getchar();
    while(c != 'A' && c != 'B') c = getchar();
    return c;
}
struct zzz {
    int l, r;
    bool operator < (const zzz &y) const { return r < y.l; }
}; set <zzz> q;
int main() {
    int m = read();
    while(m--) {
        char opt = read_c();
        if(opt == 'A') {
            int l = read(), r = read(), cnt = 0;
            zzz k = (zzz){l, r};
            set<zzz> :: iterator it = q.find(k);
            //将相交的区间全都删去
            while(it != q.end()) {
                ++cnt; q.erase(it);
                it = q.find(k);
            }
            q.insert(k);
            printf("%d\n", cnt);
        }
        else printf("%d\n", q.size());
        
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/wxl-Ezio/p/11011374.html