任重而道远
AC代码(multiset直接实现BST):
#include<cstdio>
#include<set>
using namespace std;
struct node {
int x, y;
bool operator < (const node& trs) const {
return x < trs.x || (x == trs.x && y < trs.y);
}
};
multiset<node> S;
multiset<node> :: iterator it;
int T, n, x, y;
int main () {
scanf ("%d", &T);
for (int cas = 1; cas <= T; cas++) {
if (cas > 1) printf ("\n");
printf ("Case #%d:\n", cas);
scanf ("%d", &n);
S.clear ();
while (n--) {
scanf ("%d%d", &x, &y);
node N = (node) {x, y};
it = S.lower_bound (N);
if (it == S.begin () || (--it) -> y > y) {
S.insert (N);
it = S.upper_bound (N);
while (it != S.end () && it -> y >= y) S.erase (it++);
}
printf ("%d\n", S.size ());
}
}
}