洛谷2161 會場預約 題解
阿新 • • 發佈:2018-04-05
所有 OS ase 之前 刪除 clas 修改 水過 per
好吧,用stl水過了一道題。
顯然,每一次進行修改之前的所有預約一定是沒有互相覆蓋的。
我們用set保留所有的預約,這樣在詢問時只要輸出set的size就行了
對於每次的新預約,我們就先找到右端點大於該區間左端端點的區間,然後一個一個刪除矛盾的預約就行了
復雜度大概為O(n(logn)^2)
(BZOJ上這道題居然要權限,太惡心了。)
# include<set> # include<cstdio> # include<algorithm> # include<iostream> using namespace std; struct xianduan{int l,r; bool operator <(const xianduan&rhs)const{ if(r!=rhs.r)return r<rhs.r; return l<rhs.l; } }; set<xianduan>s; int n; char c; int main(){ ios::sync_with_stdio(false); cin>>n; set<xianduan>::iterator it; while(n--){ cin>>c; if(c==‘A‘){ int l,r,ans=0; cin>>l>>r; it=s.lower_bound((xianduan){0,l}); while(it!=s.end() && r>=it->l){ ++ans; s.erase(it); it=s.lower_bound((xianduan){0,l}); } cout<<ans<<endl; s.insert((xianduan){l,r}); }else cout<<s.size()<<endl; } return 0; }
洛谷2161 會場預約 題解