思路:大白上的题...平衡树的应用



#include<iostream>
#include<cstdio>
#include<set>
#include<memory>
using namespace std;
struct Point
{
	int x,y;
	Point(int xx,int yy):x(xx),y(yy){}
	bool operator < (const Point&rhs)const
	{
		return x < rhs.x || (x==rhs.x)&&y<rhs.y;
	}
};
multiset<Point>s;
int main()
{
    int T,cas=1;
	scanf("%d",&T);
	while(T--)
	{
		if(cas>1)
			printf("\n");
		printf("Case #%d:\n",cas++);
		int n;
		scanf("%d",&n);
		s.clear();
		for(int i = 1;i<=n;i++)
		{
			int x,y;
			scanf("%d%d",&x,&y);
			Point a = Point(x,y);
			multiset<Point>::iterator it = s.lower_bound(a);
			if(it==s.begin() || (--it)->y > y)
			{
				s.insert(a);
				it = s.upper_bound(a);
				while(it!=s.end() && it->y>=y)s.erase(it++);
			}
			printf("%d\n",s.size());
		}
	}
}