P2161 [SHOI2009]會場預約
阿新 • • 發佈:2018-11-05
bound iterator lse cst con c++ ins %d pri
這一題是用來練習stl的,,,
stl的set固然很方便, 但是在c++98裏erase好像是沒有返回值的, 不能像c++11一樣
it = S.erase(it);
所以c++98裏刪掉以後最好重新找以防RE.
具體在這道題中, 就是每一次lower_bound以後看看能不能刪前面的或者後面的.
c++98真是反人類啊...什麽時候noip能夠用c++11呢.
#include <set> #include <cstdio> #include <cstring> #include <cassert> #include <iostream> #include <algorithm> using namespace std; typedef pair<int, int> P; const int MAXN = 200000 + 10; inline int read(){ char ch = getchar(); int x = 0; while(!isdigit(ch)) ch = getchar(); while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x; } int N; set<P> S; int main(){ // freopen("p2161.in", "r", stdin); // freopen("p2161.out", "w", stdout); cin>>N; while(N--) { char opt; scanf(" %c", &opt); if(opt == 'A') { int l = read(), r = read(); P cur = P(l, r); int cnt = 0; set<P>::iterator it; while(true) { it = S.lower_bound(cur); bool flag = false; if(it->first <= r && it->second >= l) ++cnt, S.erase(it), flag = true; it = S.lower_bound(cur); if(it != S.begin()) { --it; if(it->first <= r && it->second >= l) ++cnt, S.erase(it), flag = true; } if(!flag) break; } S.insert(cur); printf("%d\n", cnt); } else printf("%d\n", (int)S.size()); } return 0; }
P2161 [SHOI2009]會場預約