看了前边大佬的题解才过。 本题就是每次对新队伍查询,具体操作前边题解已经很清楚了。 ||注释有部分解释

//关于a越大b越小,因为s中维护的是a或b有一个与当前队列相等或等更小,所以若想要a更大,则b必定不会大于比此队伍的a还要小的队伍,否则不会进入集合s
#include<iostream>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<vector>
#include<iomanip>
#include<queue>
#include<set>
typedef long long ll;
const double eps = 1e-4;
using namespace std; 
struct node
{
	int a, b;
	bool operator < (const node& x) const//重写比较方法,先a后b。
	{
		if (x.a == a)
			return b < x.b;
		else
			return a < x.a;
	}
};

multiset<node> s;
int main()
{
	int t; cin >> t; int cnt = 0;
	while (t--)
	{
		s.clear();
		cnt++;
		cout << "Case #" << cnt << ":  " << endl;
		int n; cin >> n;
		for (int i = 1; i <= n; i++)
		{
			node x;
			cin >> x.a >> x.b;
			auto it = s.lower_bound(x);//a,b都相等或第一个it->a>x.a的迭代器
			if (it == s.begin() || ((--it)->b > x.b))
			{
				s.insert(x);
				auto it = s.upper_bound(x);
				while (it != s.end() && it->b >= x.b)
				{
					s.erase((it++));
				}
			}
			cout << s.size() << endl;
		}
		cout << endl;
	}
	return 0;
}